0 votes

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?

Godot version 3.2.3
in Engine by (22 points)

1 Answer

+1 vote
Best answer

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

by (2,432 points)
selected by

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

It is actually not what I expected :P
getnode() 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 getnode("car") straight in function, You wouldnt have to rerun function, because getnode 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 $

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.