Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GD0202: The parameter of the delegate signature of the signal is not supported

规则 ID

GD0202

类别

用法

修复是中断修复还是非中断修复

Breaking - If the parameter type is changed

Non-breaking - If the [Signal] attribute is removed

默认启用

原因

An unsupported type is specified for a parameter of a delegate annotated with the [Signal] attribute when a Variant-compatible type is expected.

规则说明

Every signal parameter must be Variant-compatible so it can be marshalled when emitting the signal and invoking the callbacks.

class SomeType { }

// SomeType is not a valid parameter type because it doesn't derive from GodotObject,
// so it's not compatible with Variant.
public void InvalidSignalEventHandler(SomeType someType);

// System.Int32 is a valid type because it's compatible with Variant.
public void ValidSignalEventHandler(int someInt);

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

如何解决冲突

To fix a violation of this rule, change the parameter type to be Variant-compatible or remove the [Signal] attribute from the delegate. Note that removing the attribute will mean the signal is not registered.

小技巧

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.

何时禁止显示警告

Do not suppress a warning from this rule. Signal delegates with parameters that can't be marshalled will result in runtime errors when emitting the signal or invoking the callbacks.