Last active
October 12, 2017 15:49
-
-
Save KonTrax/f01cfe7ff16a8bab0af3 to your computer and use it in GitHub Desktop.
Dynamic Script Execution Manager Source: http://gamedevrant.blogspot.no/2013/07/unity3d-change-scripts-execution-order.html
This file contains hidden or 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
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