Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add this to a MonoBehaviour to set its Script Execution Order without access to the editor.
#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
You can’t perform that action at this time.