Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 790 Bytes

UNT0015.md

File metadata and controls

33 lines (24 loc) · 790 Bytes

UNT0015 Incorrect method signature with InitializeOnLoadMethod, RuntimeInitializeOnLoadMethod or DidReloadScripts attribute

Unity needs a method decorated with InitializeOnLoadMethod, RuntimeInitializeOnLoadMethod or DidReloadScripts attribute to be static and parameterless. Otherwise either Unity won't call it or will throw NullReferenceException.

Examples of patterns that are flagged by this analyzer

using UnityEditor;

class Loader
{
    [InitializeOnLoadMethod]
    private void OnLoad(int foo, string bar) {
    }
}

Solution

Fix method signature:

using UnityEditor;

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

A code fix is offered for this diagnostic to automatically apply this change.