Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
GD0203: The delegate signature of the signal must return void¶
规则 ID |
GD0203 |
类别 |
用法 |
修复是中断修复还是非中断修复 |
Breaking - If the return type is changed Non-breaking - If the |
默认启用 |
是 |
原因¶
A delegate annotated with the [Signal] attribute has a return type when
void was expected.
规则说明¶
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.
// 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.
如何解决冲突¶
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.
小技巧
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 that return something will result in unexpected runtime errors.