Skip to content

Instantly share code, notes, and snippets.

@FlaShG
Last active July 4, 2018 16:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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