Posts

Showing posts from July, 2022

SortedAction - Guaranteeing order of execution in pure C# delegate

Image
There is something comforting about looking at a UnityEvent when serialized in Unity Editor's Inspector. It executes the actions assigned to it from top to bottom, in that order. No runtime accident can happen, this order of execution is pretty much guaranteed. Order of execution can make or break the logic of any program - did you refresh the money label before or after you subtract the amount of money paid for a restaurant meal? Order of execution is such an important concern that rearranging the actions on UnityEvent has been a recurring question asked many times on the Unity official forum, and a feature implemented by just as many packages . Order of execution is serious business. How then do we control order of execution without UnityEvent ? Surely you will encounter scenarios even within a Unity project where you have only access to pure C# delegates, such as a static event. In a pure C# delegate, actions are invoked in the ordered they are registered. This presents all...