Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 1.04 KB

USP0012.md

File metadata and controls

34 lines (24 loc) · 1.04 KB

USP0012 Don't flag private methods decorated with InitializeOnLoadMethodAttribute, RuntimeInitializeOnLoadMethodAttribute or DidReloadScripts as unused

Methods decorated with InitializeOnLoadMethodAttribute or RuntimeInitializeOnLoadMethodAttribute attributes are not unused.

Suppressed Diagnostic ID

IDE0051 - Remove unused private members

Examples of code that produces a suppressed diagnostic

using UnityEngine;
using UnityEditor;

class Loader
{
    [InitializeOnLoadMethod]
    private static void OnProjectLoadedInEditor()
    {
    }

    [RuntimeInitializeOnLoadMethod]
    private static void OnSceneLoadedAndGameRunning()
    {
    }
}

Why is the diagnostic reported?

The IDE cannot find any references to the methods OnProjectLoadedInEditor and OnSceneLoadedAndGameRunning, and believes them to be unused.

Why do we suppress this diagnostic?

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