Add this to a MonoBehaviour to set its Script Execution Order without access to the editor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
private const int executionOrder = -1000; | |
[UnityEditor.InitializeOnLoadMethod] | |
private static void SetScriptOrder() | |
{ | |
var go = new GameObject("Temp"); | |
var monoScript = UnityEditor.MonoScript.FromMonoBehaviour(go.AddComponent<NAME_OF_THIS_MONOBEHAVIOUR>()); | |
if (UnityEditor.MonoImporter.GetExecutionOrder(monoScript) != executionOrder) | |
{ | |
UnityEditor.MonoImporter.SetExecutionOrder(monoScript, executionOrder); | |
} | |
DestroyImmediate(go); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment