How are signals meant to be used to decouple nodes?

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

I’m still learning Godot, so please forgive me, if my questions sound stupid. It’s not on purpose, it’s just me in this case. :wink:

As far as I read about it, it seems to me that the signaling system is implemented only half way when it comes to decoupling nodes.

While it is fantastic that every node can emit signals (build-in and custom) at any time, it is a bit odd to me, that the receiving node has to know exactly(!) which node emits a certain signal in order to receive it. (If I understood the mechanism correctly.)
That is not, what I would call “loose coupling”.

In my opinion the receiving node should only register itself for a certain signal at a central object in the system, let’ call it SignalHUB, and receive information no matter who emitted the signal. That would really decouple it from the emitter and would probably work across the whole application.

I’m sure one could implement such a central SignalHUB quite easily with GDScript and place it near the root of the project. But I’m wondering some things:

  1. Does Godot maybe already have such a central signal distributor that could be used for such an approach?
  2. Would you recommend the use of this pattern as it creates a possible bottle neck at the central SignalHUB node?
  3. Would you encourage the use of signals in general to control ALL (inter)actions in a middle to large application? (Or should the use of signals be limited to a number of usecases?)

Edit: corrected typo

:bust_in_silhouette: Reply From: flurick

This is super much up to how you prefer to work. I myself try to use signals between scenes that are connected at the time of instancing into an active scene. It seems to be a smoother experience to connect signals via code compared to the GUI.

It is worth mentioning that groups are very nice to work with if you are doing something more “instance-specific” (?) that would need a "SignalHUB "

Thanks for your feedback.

I think it’s not that much if you design your application to work with signals from scratch.

But shortly after I posted my question I read about node groups and the possibility to trigger methods on all nodes that belong to a given group.
This does indeed seem to work better to decouple event emitter and event consumer in Godot.

Of course node groups are probably limited to synchronous events whereas signals are (or could also be?) processed asynchronously. This could make a difference in performance if there are many events/signals.

NoobOfTheDay | 2019-03-31 09:55