How to make RPC play nice with subclasses / imports?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cosine

I have this:

extends Node
onready var encapsulation_is_good = preload("res://").new()

sync func thing():
# How can I rpc("thing") from

Any way to make rpc play nice with imports?

I’d rather not have to combine into 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 doesn't exist (if I extend Node, then !is_in_tree or whatever)
:bust_in_silhouette: Reply From: hilfazer

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 as a child first. Of course needs to be in SceneTree too :slight_smile:

If you want to add as a child in _ready() you need to make a deferred call like this:

func _ready():
    call_deferred( "add_child", encapsulation_is_good )

Deferred call is needed because SceneTree is locked during _ready() calls. I’m almost sure it’s same for _enter_tree() callback.
Yes, 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.

Cosine | 2018-02-19 17:08