Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
GD0103: The exported member is read-only¶
Regel-ID |
GD0103 |
Kategorie |
Verwendung |
Breaking- oder nicht-Breaking-Fix |
Non-breaking |
Standardmäßig aktiviert |
Ja |
Ursache¶
A read-only member is annotated with the [Export]
attribute. Read-only members
can't be exported.
Beschreibung der Regel¶
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; }
Wie man Verstöße behebt¶
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.
Wann Warnungen unterdrückt werden sollten¶
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.