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
派生的类型必须具有唯一路径,否则引擎无法通过路径加载脚本,从而导致意外的运行时错误。