Topic was automatically imported from the old Question2Answer platform.
Asked By
Cosine
I have this:
a.gd:
extends Node
onready var encapsulation_is_good = preload("res://b.gd").new()
b.gd:
sync func thing():
print("here")
# How can I rpc("thing") from b.gd??
Any way to make rpc play nice with imports?
I’d rather not have to combine b.gd into a.gd as its over 100 lines. I messed around with signals but that was a feat of its own. Other things that don’t work:
rpc("thing")
# rpc doesn't exist (if I extend Node, then !is_in_tree or whatever)
I can’t see Your code but it looks like encapsulation_is_good is not on SceneTree, thus it can’t call RPCs. Try adding it to a.gd as a child first. Of course a.gd needs to be in SceneTree too
If you want to add b.gd as a child in _ready() you need to make a deferred call like this:
Deferred call is needed because SceneTree is locked during _ready() calls. I’m almost sure it’s same for _enter_tree() callback.
Yes, b.gd needs to extend Node.
Thanks a lot!! <3
I can’t believe it didn’t occur to me to, just put it in the scene tree.
One thing to note for anyone reading this: I had to set_network_master on the child node so I could use the master and slave keywords; it didn’t happen automatically.