Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GD0104: The exported property is write-only

规则 ID

GD0104

类别

用法

修复是中断修复还是非中断修复

Non-breaking

默认启用

原因

A write-only property is annotated with the [Export] attribute. Write-only properties can't be exported.

规则说明

Godot doesn't allow exporting write-only properties.

private int _backingField;

// Write-only properties can't be exported.
[Export]
public int InvalidProperty { set => _backingField = value; }

// 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, make sure the property declares both a getter and a setter, or remove the [Export] attribute.

何时禁止显示警告

Do not suppress a warning from this rule. Write-only members can't be exported so they will be ignored by Godot, resulting in runtime errors.