Connecting Signal to Non-Compatible Method

Godot Version

4.2 - 4.3

Question

Hi, I have a script with a signal that is emitted when a value needs to change:

[Signal]
public delegate void ValueChangedEventHandler();

A method emits the signal with an extra argument called Value:

EmitSignal(SignalName.ValueChanged, Value);

The signal is supposed to be handled by a simple method taking an int value:

public void UpdateValues(int value) { /* logic goes here */}

When I tried to connect the signal to UpdateValues(int), it did not appear in the available method list while “Compatible Methods Only” is selected, but is visible when it is deselected.
The obvious solution is to update my signal to accept the int argument:

public delegate void ValueChangedEventHandler(int value);

However, I noticed that UpdateValues still works when I pass Values with EmitSignal, even if I leave the initial signal without any (int) parameter.

  1. Is it normal that it works?
  2. Is it a bad practice to leave my signal without a parameter?

The only reason that I can think of is that not specifying a parameter gives the flexibility to use the signal in both cases, while adding a parameter makes it mandatory. But I am curious what I might be missing.

In GDScript it causes a stack trace, maybe C# ignores the extra parameter as a quirk.

It’s good practice to not implicitly ignore parameters, in the advanced signal connection settings you can unbind a specified amount of parameters to mark your intention to explictly drop parameters.

I don’t think there is anything in Godot’s source code that goes particularly wrong, more of a forcing best practices thing.

1 Like