@hbernal said:
@TwistedTwigleg , thank you! This is working for me once the pet instance has been created.
I am also having a similar issue with updating my HUD when the pet is caught by the player. I tried the above approach (this time with pet being added to a group and use the connect method in the HUD script). But since the HUD's on_ready() function is called before the Pet's on_ready(), it doesn't work.
Is there a similar approach I could try?
Thank you!
Great, I'm glad it worked! :smile:
For the HUD and pet, what you may want to do is try to connect the signals in _process
and use a boolean to detect if the signal has been connected or not for faster compares (to minimize the performance impact).
Something like this (pseudo code):
var is_signals_connected = false
var signal_connection_tries = 0
func _process(delta):
if is_signals_connected == false:
signal_connection_tries += 1
if (signal_connection_tries >= 10):
print("ERROR - could not connect signals in ", name, " after 10 tries!")
var nodes_in_group = get_tree().nodes_in_group("group_here")
if (nodes_in_group.size() > 0):
nodes_in_group[0].connect(...) # connect signal
is_signals_connected = true
With it running in _process
it should execute after all the nodes have executed in _ready
, and by doing it until the signals are connected, even if there is a bit of setup needed afterwards it should still properly connect as long as the HUD/Pet is added to the correct groups in _ready, regardless of the scene order.