PostLateUpdateGroup / custom PlayerLoop point group

Is there a way to insert a custom group into specific player loop point somehow?

Context:
I’ve got a following issue where canvas update logic happens after results of the data processing has been written. As a result, its a visible frame skip and I’d like to avoid it by modifying results after Canvas.willRenderCanvases. (E.g. in PostLateUpdate)

Edit: Ended up hacking logic around the callback, but it would be great to have UI events split into groups as well.

ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoop

2 Likes

This is what I’ve been looking for. Thank you.

A caveat of adding extra “root” group is that in 0.51 Systems window breaks (but I guess you already know that, I’ve found your post). Fortunately old Entity Debugger still works, so no big deal. Another reason to migrate to 1.0;

For the future readers, here’s how I’ve added it:
0. You need a custom bootstrap.

  1. PostLateUpdateGroup looks like this:
/// <summary>
/// PostLateUpdateGroup that runs after LateUpdate
/// </summary>
public class PostLateUpdateGroup : ComponentSystemGroup { }
  1. Inside your custom bootstrap insert group into the player loop & make sure you remove that same group from the simulation group. Otherwise group will update twice, via SimulationGroup & PostLateUpdate ScriptBehaviourUpdate callback. Don’t use CreateSystem for the group - that will create another system group as all groups types are detected and created up automatically upon world creation. (or use GetOrCreateSystem instead)

AppendSystemToPlayerLoop adds group after all native engine groups. So no need to perform any custom sorting. This might change in the future though.

var postLateUpdateGroup = world.GetExistingSystem<PostLateUpdateGroup>();

var playerLoop = PlayerLoop.GetCurrentPlayerLoop();
ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoop(postLateUpdateGroup, ref playerLoop, typeof(PostLateUpdate));
PlayerLoop.SetPlayerLoop(playerLoop);
  
simulationSystemGroup.RemoveSystemFromUpdateList(postLateUpdateGroup);
  1. Put required systems / groups into PostLateUpdateGroup. Groupping & sorting should work just fine inside the group.
1 Like