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...
GD0003:在同一個腳本檔案中找到多個同名的類別
規則 ID |
GD0003 |
分類 |
用法 |
修正是否會破壞相容性 |
非破壞性 |
預設啟用 |
是 |
原因
一個腳本檔案中包含多個名稱與檔案名相同、且繼承自 GodotObject 的型別。每個腳本檔案只能有一個型別名稱與檔案名稱相同。
規則說明
Godot 要求腳本路徑唯一,因此每個型別必須定義在自己的檔案中,且型別名稱需與檔案名稱相符。
public partial class MyNode : Node { }
namespace DifferentNamespace
{
// Invalid because there's already a type with the name MyNode in this file.
public partial class MyNode : Node { }
}
// Invalid because there's already a type with the name MyNode in this file.
public partial class MyNode<T> : Node { }
修正方式
要修正此規則的違規情形,請將每個型別宣告移至不同的檔案中。
什麼時候應該忽略警告
請勿忽略此規則的警告。繼承自 GodotObject 的型別必須有唯一的路徑,否則引擎將無法正確載入腳本,造成執行階段錯誤。