Signal up and call down with singleton

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

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

:bust_in_silhouette: Reply From: njamster

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.