USP0006 Don't flag private fields decorated with serialization attributes (like SerializeField, SerializeReference or OdinSerialize) as unused
June 17, 2025 ยท View on GitHub
Private fields with the SerializeField, SerializeReference or OdinSerialize attributes should not be marked as unused.
Suppressed Diagnostic ID
IDE0051 - Remove unused private members
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 used within the project. Therefore, under normal circumstances, it would be reasonable to remove the unused code.
Why do we suppress this diagnostic?
A field with the SerializeField, SerializeReference or OdinSerialize attributes are exposed and can be used in the Unity Inspector.