Topic was automatically imported from the old Question2Answer platform.
Asked By
simonlee
What happens or what is the side effect (if any) to connect the same signal to the same node and callable, multiple times?
For example:
var nodes = get_tree().get_nodes_in_group("group-name")
for n in nodes:
n.mouse_entered.connect(_handleMouseOverFx.bind(n))
Will the callable be “re-assigned” to the node if already connected? Does it work the same way as assigning the same value to the same variable multiple times?
Or, will the node have multiple references to the same Callable?
This is the sort of thing you can test in a sandbox project in 2 minutes.
Godot 3.x threw an error if you tried to connect to an already existing function, I don’t see why it would be any different in 4.0.
Correction to my own comment below… @zhyrin is right. The engine will throw an error when trying to connect the same signal more than once. It will not crash the game, but will output the error to the ERRORS tab, as in:
E 0:00:01:0036 Lobby.gd:291 @ _connectControlsFxSignal(): Signal 'mouse_entered' is already connected to given callable 'Control(Lobby.gd)::_playMouseOverFx' in that object.
Right… I made a simple test.
Added a new button, a couple functions and connected them like so: