Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved PostLateUpdateGroup / custom PlayerLoop point group

Discussion in 'Entity Component System' started by xVergilx, Jun 28, 2023.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    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.
     
    Last edited: Jun 28, 2023
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,975
    ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoop
     
    bb8_1 and xVergilx like this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    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:
    Code (CSharp):
    1. /// <summary>
    2. /// PostLateUpdateGroup that runs after LateUpdate
    3. /// </summary>
    4. public class PostLateUpdateGroup : ComponentSystemGroup { }
    2. 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.
    Code (CSharp):
    1. var postLateUpdateGroup = world.GetExistingSystem<PostLateUpdateGroup>();
    2.  
    3. var playerLoop = PlayerLoop.GetCurrentPlayerLoop();
    4. ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoop(postLateUpdateGroup, ref playerLoop, typeof(PostLateUpdate));
    5. PlayerLoop.SetPlayerLoop(playerLoop);
    6.  
    7. simulationSystemGroup.RemoveSystemFromUpdateList(postLateUpdateGroup);
    3. Put required systems / groups into PostLateUpdateGroup. Groupping & sorting should work just fine inside the group.
     
    Last edited: Jun 29, 2023
    bb8_1 likes this.