Skip to content

GD0203: The delegate signature of the signal must return void

Value
Rule IDGD0203
CategoryUsage
Fix is breaking or non-breakingBreaking - If the return type is changed
Non-breaking - If the [Signal] attribute is removed
Enabled by defaultYes

Cause

A delegate annotated with the [Signal] attribute has a return type when void was expected.

Rule description

Every signal must return void. There can be multiple callbacks registered for each signal, if signal callbacks could return something it wouldn't be possible to determine which of the returned values to use.

csharp
// This signal delegate is invalid because it doesn't return void.
public int InvalidSignalEventHandler();

// This signal delegate is valid because it returns void.
public void ValidSignalEventHandler();

Take a look at the C# signals documentation for more information about how to declare and use signals.

How to fix violations

To fix a violation of this rule, change the delegate to return void or remove the [Signal] attribute from the delegate. Note that removing the attribute will mean the signal is not registered.

TIP

If the signal doesn't need to interact with Godot, consider using C# events directly. Pure C# events allow you to use any C# type for its parameters.

When to suppress warnings

Do not suppress a warning from this rule. Signal delegates that return something will result in unexpected runtime errors.