USP0019 Don't flag private members decorated with implicit-usage attributes as unused

June 17, 2025 ยท View on GitHub

Members decorated with PreserveAttribute, UsedImplicitlyAttribute or CreatePropertyAttribute attributes are not unused.

Suppressed Diagnostic ID

IDE0051 - Remove unused private members

Examples of code that produces a suppressed diagnostic

using UnityEngine;
using UnityEgine.Scripting;

class Loader
{
    [PreserveAttribute]
    private void InvokeMe()
    {
    }

    public string Name; // "InvokeMe" serialized
    private void Update() {
        Invoke(Name, 0);
    }
}

Why is the diagnostic reported?

The IDE cannot find any references to the method InvokeMe and believes it to be unused.

Why do we suppress this diagnostic?

Even though the IDE cannot find any references to InvokeMe , it will be called by Unity, and should not be removed.