Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 978 Bytes

File metadata and controls

26 lines (17 loc) · 978 Bytes

USP0004 Don't flag fields decorated with serialization attributes (like SerializeField, SerializeReference or OdinSerialize) as read-only

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.