Call a function without taking arguments into account

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

In my project, I have a Node containing a “level clear” function that I just drop in whatever level can be cleared. All this function does is print a congratulatory message on the screen and loads the next level, so it really does not matter in which way it got triggered and what arguments it received.

So now I’d like to trigger this function using various regular signals from other Nodes placed in the level, for example:
Button: on button down
Area2D / CollisionShape: on body entered
Timer: Timeout
…and so on.

The problem is that some of these signals emit arguments with them too, for example “on body entered” emits “body”, while “timeout” doesn’t emit anything. Or later some signals might send some other arguments too that I haven’t thought of yet.

Is there a way to make this “level clear” function make an exception and ignore the arguments if they are not needed? I have read about it elsewhere on internet but it’s either outdated or incomprehensible to me.

If you connect the signal in the editor you can toggle the advanced settings and there’s a “unbind signal arguments” option, so the signal will not send the arguments you unbind.

In code you can do it like this:
signal.connect(your_function.unbind(1)) ← this will unbind one argument, if the signal passes more arguments then you have to set the correct number.

2 Likes

Thank you, this works, now I know how to use it!

1 Like