Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@FlaShG
Last active July 4, 2018 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlaShG/67084b22246def70cf6b96bdea2fc669 to your computer and use it in GitHub Desktop.
Save FlaShG/67084b22246def70cf6b96bdea2fc669 to your computer and use it in GitHub Desktop.
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