USP0010 Don't flag fields decorated with the ContextMenuItem attribute as unused

June 17, 2025 ยท View on GitHub

Fields decorated with the ContextMenuItem attribute are not unused.

Suppressed Diagnostic ID

IDE0051 - Remove unused private members

Examples of code that produces a suppressed diagnostic

using UnityEngine;

class Camera : MonoBehaviour
{
    [ContextMenuItem("Foo", "Bar")]
    private string contextMenuString = "";
}

Why is the diagnostic reported?

The IDE cannot detect any references to contextMenuString in the class.

Why do we suppress this diagnostic?

contextMenuString is used indirectly by Unity, which is undetectable by the IDE.