GD0103:导出的成员是只读的

规则 ID

GD0103

类别

用法

修复是破坏性的还是非破坏性的

非破坏性的

默认启用

原因

只读成员用 [Export] 属性注解。只读成员无法被导出。

规则说明

Godot 不支持导出只读成员。

// Read-only fields can't be exported.
[Export]
public readonly int invalidField;

// This field can be exported because it's not declared 'readonly'.
[Export]
public int validField;

// Read-only properties can't be exported.
[Export]
public int InvalidProperty { get; }

// This property can be exported because it has both a getter and a setter.
[Export]
public int ValidProperty { get; set; }

如何解决违规情况

要修复字段中违反该规则的情况,请移除 readonly 关键字或移除 [Export] 属性。

要修复属性中违反该规则的情况,请确保属性同时声明了 getter 和 setter,或者移除 [Export] 属性。

何时抑制警告

不要抑制该规则的警告。只读成员无法被导出,因此它们将被 Godot 忽略,从而导致运行时错误。