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...
GD0401:類別必須繼承自 Godot.GodotObject 或其衍生類別
規則 ID |
GD0401 |
分類 |
用法 |
修正是否會破壞相容性 |
破壞性變更 - 若更改繼承鏈 非破壞性變更 - 若移除 |
預設啟用 |
是 |
原因
被 [GlobalClass] 屬性標註的型別沒有繼承自 GodotObject。
規則說明
對於未繼承自 GodotObject 的型別,[GlobalClass] 屬性無效。每個 全域類別 最終都必須繼承自 GodotObject,才能被正確處理。
// 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] 屬性。
什麼時候應該忽略警告
請勿忽略此規則的警告。將 [GlobalClass] 加到未繼承自 GodotObject 的型別很容易出錯,此警告可協助使用者避免導致不可預期錯誤。