Autoload Signal Bus vs In Scene Signal Connections

Godot Version

3.6

Question

I need some insight on how to handle connecting signals between child components of scenes loaded in as nodes. I’ve been working on a tactics game that uses custom state machine nodes to determine what the different parts of the game should do (character behavior, UI, etc.). Due to the nature of the game, I found that it made the most sense to have the state of one node be influenced by the state of another node. For example, when a player character starts their turn, the UI would then need to update to display the character details.

What I am having trouble with is what approach to take with connecting the signals of these state machines. I’ve seen other posts that recommend using a signal bus as an autoload that stores the signals that connect the nodes. This is the approach I first used. While this is easy to implement, it doesn’t sit right with me that I am essentially making global access signals that are only used in one scene. With this in mind, I modified the project so that the signals are now connected to each other directly. While the signals are no longer “global”, the current implementation is not the cleanest.

What thoughts do you have on these different approaches?

As a personal preference, I avoid using a global signal bus whenever possible. Currently the only global signal I use is one for changing to a different scene.

If you have a scene with children, you can have that scene subscribe to the signals the children send and do all the processing in the scene. I have this code in a base class for the scenes where the player is engaged in combat:

player.game_over.connect(game_over)
player.combat_data_update.connect(combat_data_update)
player.screen_exited.connect(screen_exited)

If I was using signals in a state machine I would take a similar approach. The machine would handle all the signal processing and would change the signals it listens to every time the state changes.

1 Like