When to use Signals vs Callable? (best practices)

Godot Version

Godot version 4.3

Question

Is this situation the correct use of Signals in Godot? (ie, best practice?)

The goal with this pseudo code is when a new level loads a number of other nodes needs to do things. One is the player needs to be set to the starting point of the level. (each level can have different coordinates for the player starting point)

  1. Load a new level via gdscript. (add_child, etc…)
  2. Level node (on _ready()) emits custom signal “level_loaded” and passes a reference to itself as a parameter.
  3. Player node (on _ready() ) has connected to the signal “level_loaded” to call “_level_loaded” on player.gd.
  4. Player node moves itself to the start position in the level. (ie, using data accessible via the passed parameter)

Or should I use a Callable?

I’ve read the docs on Signals, and it’s explicit about being “past tense” and “not intended to start actions”. Is that what this situation is from a Godot perspective?

Is the better option for the level node to get a reference to the player node and directly call a function on the player node? This seems more tightly coupled, which is also not best practices…

Thanks for any help on this!

The way you described it sounds good to me.
I wouldn’t use Callables here, as the Signals serve almost the same purpose as you’d achieve with Callables.
Also, calling a function on another node should ideally be avoided, as you mentioned already - it’s better to keep them decoupled with signals.

1 Like

Thanks!