Direct access via global or signal

Godot Version

4.2.2

Question

I want to know your opinion. I am using access from one object to another via direct access. I add an object to a variable, then call a function on this object. For example, I access a level from a character via global, simply writing the level into a variable when loading it.
There is an option to use signals. Which approach is better?

Hi! I think that depends on what you want to do. If you have side effects that need to know that the variable changed, or you want to automatically trigger other functions, use signals. If you only need to change this one variable without dependencies to others, do it directly.
Perhaps you can give us more details?

1 Like

I don’t use signals at all, only standard ones. I call functions in the object through direct access. If I need to call a group of objects, I use call_group. So I thought about it - it’s not for nothing that signals were invented. Maybe they are processed faster by the engine than access through a variable.

Signals have two advantages over direct function calls: a signal can have multiple listeners connected to it, and the code emitting the signal doesn’t have to know what the listeners are. In cases where you don’t need either advantage, use direct function calls.

1 Like

That is, signals have the same benefits as a group call. Right? Can we say that this is a complete group calling alternative?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.