GD0401: The class must derive from Godot.GodotObject or a derived class
规则 ID |
GD0401 |
类别 |
用法 |
修复是破坏性的还是非破坏性的 |
更改继承链会导致中断性变更 非中断性变更——如果移除 |
默认启用 |
是 |
原因
A type annotated with the [GlobalClass]
attribute does not derive from
GodotObject
.
规则说明
The [GlobalClass]
has no effect for types that don't derive from GodotObject
.
Every global class must ultimately derive from
GodotObject
so it can be marshalled.
// This type is not registered as a global class because it doesn't derive from GodotObject.
[GlobalClass]
class SomeType { }
// This type is a global class because it derives from Godot.Node
// which ultimately derives from GodotObject.
[GlobalClass]
class MyNode : Node { }
// This type is a global class because it derives from Godot.Resource
// which ultimately derives from GodotObject.
[GlobalClass]
class MyResource : Resource { }
如何解决违规情况
欲解决该规则带来的冲突,请避免在并未继承自 GodotObject
或移除``[GlobalClass]`` 属性。
何时抑制警告
Do not suppress a warning from this rule. Adding the [GlobalClass]
to a type
that doesn't derive from GodotObject
is an easy mistake to make and this
warning helps users realize that it may result in unexpected errors.