Why do I need to reload direct references but not Signals?

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

Hey everyone, I have stumbled upon the following situation:

I have a parent Node that interacts with scripts from child nodes. Sometimes I delete these child nodes and replace them with others (basically saving and loading the game via PackedScene).
If I do that, I have to run a function that runs get_node() again because the current references points to null since the node was deleted, which makes sense.

What I don’t understand however is why it works if I use Signals. Shouldn’t the connect function also listen to a null node? How come I don’t have to rerun the connect functions?

:bust_in_silhouette: Reply From: Inces

And how do You reference nodes in connect function ? Aren’t You using references coming from refreshed get_node() few lines higher ?? :wink:

Ahh, I see. I connect them with $ instead of get_node(). $ Seems to work without issues.

Fjcxv21 | 2021-03-16 20:23

It is actually not what I expected :stuck_out_tongue:
get_node() is the same as $.
You propably saved the reference to some node as variable ( for example var car = get_node(“car”) and than You used this variable in another function. Your variable became unique node with ID. When You replaced nodes, function using car variable returned error, because node of this ID was missing.
If You didn’t pass reference to variable and just wrote get_node(“car”) straight in function, You wouldnt have to rerun function, because get_node would apply to any node, with any ID, as long as its path and name is “car”. Doesnt matter if it is get_node or $

Inces | 2021-03-16 22:00

Thanks a lot, that explains it. Now everything works like I want.

Fjcxv21 | 2021-03-17 20:42