Signals better or worse performance wise?

Godot Version

4.2.2

Question

Hi all,

I know that title doesn’t make sense but bear which me for a second. I learn’t one way of being able to access the variables/functions in another scene using the ol’:

@onready var camera = $"../CameraR2D2"

then accessing any vars with:

cam.this_var=false;

or functions

cam.this_function(false);

But yesterday/today I came across signals/emit and I don’t know which way is better way to access them.

What would you all recommend and which is better for performance?

Thankyou and Regards.

I think this one is good for just a single work:

cam.this_var = false;

For multi works, you can call a function. Signal are used when you create multi objects and connect them with a function like you added 2-5 enemies with codes, and connect its health_changed signal with _on_enemy_health_changed

1 Like

I’d say:

  • Use signals if many things need to listen to something happening
  • Use methods if you only need to respond or interact with one thing, and that thing can be accessed easily (so not if you have one item that can handle talking to many different types of things even though it’s just one)
2 Likes

Thankyou to both of you for taking the time to reply :sunglasses:.

Usually it was just to set a boolean value and only once or very rarely. But there are some functions that are cropping up more frequently as I progress so I’ll keep what you said in mind for the future.

Regards.

1 Like

It’s all going to depend on how tightly or loosely you want to bind your classes together. Use signals if you don’t want to tie your classes to other classes. Use direct access only if classes logically belong together all the time. And even then, you’re better off using accessor methods rather than direct access, since you can add additional access constraints and conditionals to a common location (the accessor)

The overhead added by signal is insignificant in the vast majority of cases, and the maintainability and reuseability of using signals far outweigh their trivial overhead.

1 Like