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 How to update system after SimulationSystemGroup (including EndSimulationEntityCommandBufferSystem)?

Discussion in 'Entity Component System' started by xVergilx, Jul 18, 2020.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Is there a way to do so without writing custom bootstrap?
    I've tried using UpdateAfter, but it doesn't work unfortunately.

    I want a system that runs after EndSimulationEntityCommandBufferSystem, since that system rans monobehaviours update. OrderLast on the EndSimulationECBSystem seems to be always puting it last in the group no matter what other systems attributes have.

    Also, it has to be before PresentationSystemGroup / PreLateUpdate, because that would be too late, and that causes 1 frame rendering desync.
     
    Egad_McDad likes this.
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    677
    If it can be at the very beginning of the PresentationSystemGroup (right after the BeginPresentationEntityCommandBufferSystem), yes, you can with
    [UpdateInGroup(typeof(PresentationSystemGroup), OrderFirst = true)]. If not, then you will need a custom bootstrap.
     
    Egad_McDad likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    That causes 1 frame miss, unfortunately. Okay, I guess custom bootstrap is the way to go.
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Soo, I've tried using custom bootstrap, and it doesn't seems to help.
    If I don't add my component system group (AfterSimulationGroup) to the SimulationSystemGroup while rest of the systems are added, then manually add it - it still added before EndSimulationEntityCommandBufferSystem;

    If I add AfterSimulationGroup after all systems, but before sort, its still added before EndSimulationECBSystem;

    System update lists are protected / readonly, so the only option remains is reflection?
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    I feel like the better solution is just create your own command buffer system and use that instead
     
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    My goal is to run monobehaviour update after ECS simulation is done. I cannot use that unfortunately.

    Custom monobehaviour update manager is made into one of the systems I want to put into AfterSimulationGroup;
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    I don't get why that stops you from putting a buffer system within simulation?

    BeginSimulationBufferSystem
    YourSystem1
    YourSystem2
    YourBufferSystem [use this]
    YourSystem3
    EndSimulationBufferSystem [don't use this]

    Is the same thing as

    BeginSimulationBufferSystem
    YourSystem1
    YourSystem2
    EndSimulationBufferSystem [use this]
    YourSystem3
     
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Backward compatibility? I guess.
    If something not mine, e.g. from plugin will change entities, those changes will not propagate correctly to the monobehaviours update.
     
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Okay, so I've managed to order it like I want to.
    - Had to discard EndSimulationEntitiyCommandBufferSystem via bootstrap;
    - Re-added it to the LateSimulationGroup instead via bootstrap;
    - AfterSimulationGroup runs last now;
    upload_2020-7-23_15-10-40.png

    No reflection needed, and I'll get a warning if something is not ordering correctly, which will at least will give me a hint what's wrong.
    Probably not the best solution, but it gets jobs done.
     
  10. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    What's wrong with just doing
    Code (CSharp):
    1. [UpdateInGroup(typeof( SimulationSystemGroup ), OrderLast = true)]
    2. [UpdateAfter(typeof(EndSimulationEntityCommandBufferSystem))]
    3. public class AfterSimulationSystemGroup : ComponentSystemGroup { }
    Capture.PNG
     
  11. yondercode

    yondercode

    Joined:
    Jun 11, 2018
    Posts:
    27
    It works! I haven't think of using both
    OrderLast
    and
    UpdateAfter
    at the same time. Thanks.
     
  12. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    I think I've tried that, and it just spit out warnings that EndSimulationEntityCommandBufferSystem is in the different update group. I'll try that again once I can. Thanks for the suggestion.
     
  13. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Yeah, it does work now. Wtf?
    upload_2020-7-23_20-17-49.png

    Okay, I got it. If the OrderLast is not set to true it just does this:
    Code (CSharp):
    1. Ignoring invalid [UpdateAfter] attribute on EntitiesExt.UpdateGroups.AfterSimulationGroup because Unity.Entities.EndSimulationEntityCommandBufferSystem belongs to a different ComponentSystemGroup.
    2. This attribute can only order systems that are children of the same ComponentSystemGroup.
    3. Make sure that both systems are in the same parent group with [UpdateInGroup(typeof(Unity.Entities.SimulationSystemGroup)].
    Which is weird, and probably a bug, unless intended.