Skip to content

Instantly share code, notes, and snippets.

@KonTrax
Last active October 12, 2017 15:49
Show Gist options
  • Save KonTrax/f01cfe7ff16a8bab0af3 to your computer and use it in GitHub Desktop.
Save KonTrax/f01cfe7ff16a8bab0af3 to your computer and use it in GitHub Desktop.
using UnityEditor;
[InitializeOnLoad]
public class ExecutionOrderManager : Editor
{
static ExecutionOrderManager()
{
// Get the name of the script we want to change it's execution order
string scriptName = typeof(MyMonoBehaviourClass).Name;
// Iterate through all scripts (Might be a better way to do this?)
foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
{
// If found our script
if (monoScript.name == scriptName)
{
// And it's not at the execution time we want already
// (Without this we will get stuck in an infinite loop)
if (MonoImporter.GetExecutionOrder(monoScript) != -100)
{
MonoImporter.SetExecutionOrder(monoScript, -100);
}
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment