SDT0404: Read Only Input Mapping
| Property | Value |
|---|---|
| Rule ID | SDT0404 |
| Title | Read Only Input Mapping |
| Category | Input |
| Severity | Error |
Cause
A field or property is decorated with [ActionInput] or [RangeInput], but it is declared readonly or, in the case of properties, does not have a set method.
Rule Description
When a field or property is decorated with an action- or range input attribute, it must be mutable.
How to Fix Violations
Ensure every field and property must be mutable, meaning, is not a literal expression nor a readonly member.
Violation:
public sealed class PlayerInputState : IInputReceiver
{
[ActionInput(PlayerActions.Crouch)]
public readonly bool IsCrouching = false; // Non-mutable type!
[RangeInput(PlayerActions.WalkForward)]
public float WalkForward { get; } = 0.0F; // No setter!
}
Fix:
public sealed class PlayerInputState : IInputReceiver
{
[ActionInput(PlayerActions.Crouch)]
public bool IsCrouching = false;
[RangeInput(PlayerActions.WalkForward)]
public float WalkForward { get; set; } = 0.0F;
}
When to Suppress Warnings
Danger
Do not suppress this error. Unwritable field or property mappings may cause runtime undefined behaviour when the input is triggered.