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...
GD0103: The exported member is read-only¶
规则 ID |
GD0103 |
类别 |
用法 |
修复是中断修复还是非中断修复 |
Non-breaking |
默认启用 |
是 |
原因¶
A read-only member is annotated with the [Export] attribute. Read-only members
can't be exported.
规则说明¶
Godot doesn't allow exporting read-only members.
// 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; }
如何解决冲突¶
To fix a violation of this rule for fields, remove the readonly keyword or
remove the [Export] attribute.
To fix a violation of this rule for properties, make sure the property declares
both a getter and a setter, or remove the [Export] attribute.
何时禁止显示警告¶
Do not suppress a warning from this rule. Read-only members can't be exported so they will be ignored by Godot, resulting in runtime errors.