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.
using UnityEditor;
class Loader
{
[InitializeOnLoadMethod]
private void OnLoad(int foo, string bar) {
}
}
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.