Say I have a custom playerloop that adds EarlyUpdate().
If I take a monobehaviour with [DefaultExecutionOrder(-10)] and add it’s .EarlyUpdate() method to the playerloop EarlyUpdate delegate, will execution order be respected?
I’ve searched high and low, and I’m hoping I don’t have to figure out a way to reliably test this.
void ConstructCustomUpdateLoop(PlayerLoopSystem playerLoop)
{
// Then the default update system
PlayerLoopSystem updateSystem = playerLoop.subSystemList[5]; // 5 is the index of the Update system (was 4 in 2019)
// Convert the update subsystems to a list so we can easily insert our own
var updateSubsystemList = new List<PlayerLoopSystem>(updateSystem.subSystemList);
//Add subsystems here
var actionsLoop = ConstructEarlyUpdateLoop();
var scheduleJobsSystem = ConstructPreUpdateJobScheduler();
var postUpdateLoop = ConstructPostUpdateLoop();
// Add our new subsystems to the front of the update system
//Insert earlier systems later, so they execute first
updateSubsystemList.Insert(0, scheduleJobsSystem);
updateSubsystemList.Insert(0, actionsLoop);
updateSubsystemList.Add(postUpdateLoop);
//Bake updated system into update player loop
updateSystem.subSystemList = updateSubsystemList.ToArray();
playerLoop.subSystemList[5] = updateSystem;
}
PlayerLoopSystem ConstructEarlyUpdateLoop()
{
// Create our custom subsystem
PKEarlyUpdate = new PKEarlyUpdateLoop();
PlayerLoopSystem actionLoop = new PlayerLoopSystem()
{
type = typeof(PKEarlyUpdateLoop), // The name of this type is used in the profiler,
// but there is no requirement that it is actually
// used in the update delegate
updateDelegate = () =>
{
PKEarlyUpdate.Execute();
JobHandle.ScheduleBatchedJobs();
}
};
return actionLoop;
}
public class PKCustomSubLoop
{
private List<Action> _delegates;
private List<Action> _removalBuffer;
public event Action OnTick
{
add
{
_delegates.Add(value);
}
remove
{
_delegates.Remove(value);
//_removalBuffer.Add(value);
}
}
public PKCustomSubLoop()
{
int initialCapacity = 256;
_delegates = new List<Action>(initialCapacity);
_removalBuffer = new List<Action>(initialCapacity);
}
public void Execute()
{
for (int i = 0; i < _delegates.Count; ++i)
{
_delegates[i].Invoke();
}
}
}