USP0013 Don't flag 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 by FxCop.

Suppressed Diagnostic ID

CA1823 - Remove unused fields

Examples of code that produces a suppressed diagnostic

using UnityEngine;

class Camera : MonoBehaviour
{
	[SerializeField]
	private string someField = "default";
}

Why is the diagnostic reported?

FxCop 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.