Home

Awesome

Unity3D Ordered Update

This script helps you receive Update callbacks from any of your scripts or objects, in any order. Here are some common use-cases:

Simply import OrderedUpdate.unitypackage into your project and you are good to go! Just make sure that the execution orders of OrderedUpdatePreCallback and OrderedUpdatePostCallback are correct in Edit-Project Settings-Script Execution Order:

ScriptExecutionOrder

How To

void Awake() {
	OrderedUpdate.OnPreUpdate += OnPreUpdate;
}

private void OnPreUpdate() {
	// called every frame, before other Update calls
}

void OnDestroy() {
	OrderedUpdate.OnPreUpdate -= OnPreUpdate;
}
OrderedUpdate.AddUpdateReceiver( OrderedUpdate.UpdateCallback receiver, int order );
OrderedUpdate.AddFixedUpdateReceiver( OrderedUpdate.UpdateCallback receiver, int order );
OrderedUpdate.AddLateUpdateReceiver( OrderedUpdate.UpdateCallback receiver, int order );

Method Signatures

public delegate void UpdateCallback();

public static event UpdateCallback OnPreUpdate;
public static event UpdateCallback OnUpdate;
public static event UpdateCallback OnFixedUpdate;
public static event UpdateCallback OnLateUpdate;

public static void OrderedUpdate.AddUpdateReceiver( UpdateCallback receiver, int order = 0 );
public static void OrderedUpdate.AddFixedUpdateReceiver( UpdateCallback receiver, int order = 0 );
public static void OrderedUpdate.AddLateUpdateReceiver( UpdateCallback receiver, int order = 0 );

public static void OrderedUpdate.RemoveUpdateReceiver( UpdateCallback receiver, int order = 0 );
public static void OrderedUpdate.RemoveFixedUpdateReceiver( UpdateCallback receiver, int order = 0 );
public static void OrderedUpdate.RemoveLateUpdateReceiver( UpdateCallback receiver, int order = 0 );