Tag: gdscript

Decoupled (pub-sub) messaging system in Godot

This is an explanation for how to make a decoupled messaging system using the built-in “signals” mechanism. I just started learning GDScript to do programming in Godot, and it isn’t taking me long at all. I quickly realized “signals” are a nice way of handling events, but have the downside that the object receiving events needs to know about the object that sends events. This level of coupling is fine in many situations, but a truly decoupled system (where neither the sender nor receiver know about each other) would often be even better, so I devised this simple approach to doing that.

At a high-level, you make a script with a list of your signals in it, and then set that script to Autoload (making sure Global Variable is enabled, to get the convenient variable name). In other words, something like this in the Project Settings:

Continue reading “Decoupled (pub-sub) messaging system in Godot”