+2 votes

Hey, I heard that the correct way to use signals is to "signal up and call down", but how about singletons? they are "up", but we can always access them, so using signals looks unnecessary

in Engine by (19 points)

1 Answer

+4 votes
Best answer

so using signals looks unnecessary

Then don't use any! There's no one forcing you to.

I heard that the correct way to use signals is to "signal up and call down"

That's at best a rule of thumb, not the "correct way" to do things. Actually, there is no such thing as a "correct way": you can achieve exactly the same things with both and as long as it works for you, there really isn't any reason to change something.

Thing is: If a node calls another nodes method (doesn't matter if that node is a child or a parent node) and that node doesn't exist yet/anymore/in the new context, that will lead to an error. If, on the other hand, a node merely emits a signal this will always go through as long as the node defines that signal. And it's the other nodes responsibility to connect to that signal. If you remove a connected node, nothing will break.

So under the assumption that you might end up re-using a scene in a different context (with different parent- or child-nodes) using a signal to split up responsibilities makes sense. If you're sure you won't end up in such a situation or don't mind changing a few method calls, you can achieve the same stuff with direct method calls though.

by (10,483 points)
selected by
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 Frequently asked questions and 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.