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...
GD0301: The generic type argument must be a Variant compatible type¶
规则 ID |
GD0301 |
类别 |
用法 |
修复是中断修复还是非中断修复 |
中断 |
默认启用 |
是 |
原因¶
An unsupported type is specified for a generic type argument when a Variant-compatible type is expected.
规则说明¶
When a generic type parameter is annotated with the [MustBeVariant] attribute,
the generic type is required to be a Variant-compatible type. For example,
the generic Godot.Collections.Array<T> type only supports items of a type
that can be converted to Variant.
class SomeType { }
// SomeType is not a valid type because it doesn't derive from GodotObject,
// so it's not compatible with Variant.
var invalidArray = new Godot.Collections.Array<SomeType>();
// System.Int32 is a valid type because it's compatible with Variant.
var validArray = new Godot.Collections.Array<int>();
如何解决冲突¶
To fix a violation of this rule, change the generic type argument to be a Variant-compatible type or use a different API that doesn't require the generic type argument to be a Variant-compatible type.
何时禁止显示警告¶
Do not suppress a warning from this rule. API that contains generic type arguments
annotated with the [MustBeVariant] attribute usually has this requirement
because the values will be passed to the engine, if the type can't be marshalled
it will result in runtime errors.