USP0004 Don't flag fields decorated with serialization attributes (like SerializeField, SerializeReference or OdinSerialize) as read-only
June 17, 2025 ยท View on GitHub
Fields with the SerializeField, SerializeReference or OdinSerialize attributes should not be marked read-only.
Suppressed Diagnostic ID
IDE0044 - Make field readonly
Examples of code that produces a suppressed diagnostic
using UnityEngine;
class Camera : MonoBehaviour
{
[SerializeField]
private string someField = "default";
}
Why is the diagnostic reported?
The IDE does not detect that the field is ever assigned outside of the declaration or in a constructor. Therefore, under normal circumstances, it would be reasonable to mark the field as read-only.
Why do we suppress this diagnostic?
A field with the SerializeField, SerializeReference or OdinSerialize attributes are exposed and can be assigned in the Unity Inspector. Making the field read-only would break this behavior.