I want an instanced child to have code that'll affect nodes relating to the parent node

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

I have a galaga clone in the works, and I want to make it that when you destroy an asteroid it’ll increase the score variable I have in a Hud instance that’s a child of main, the asteroids are instanced through code so I can’t use signals it seems. How would I be able to achieve what I wanna do if its possible?

:bust_in_silhouette: Reply From: jgodfrey

You can certainly use signals on nodes that are instanced via code. Why do you think you can’t?

Here’s a random example:

var r = Rock.instance()

# wire necessary signals
r.connect('explode', self, '_on_Rock_explode')
r.connect('ship_dead', $Ship, '_on_Ship_dead')

I tried to do that but it didnt seem to work


Invalid type in function ‘connect’ in base ‘RigidBody2D
(Asteroid.gd)’. Cannot convert argument 3 from Nil to String.

ThatGNamedLoughka | 2020-06-18 22:29

Nevermind I saw my error and it works now. Thank you so much!!!

ThatGNamedLoughka | 2020-06-18 22:36