Search Unity

AddManager stopped to work

Discussion in 'Entity Component System' started by sebas77, Mar 26, 2019.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    World.Active.AddManager(renderingDataSynchronizationEngine);

    doesn't work anymore (the debugger doesn't show the system and the OnUpdate is not called) any clue? (The system is with [DisableAutoCreation])
     
  2. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Did you do
    ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
    afterwards?
     
  3. jobbernowled

    jobbernowled

    Joined:
    Oct 31, 2013
    Posts:
    1
    I personally use GetOrCreateManager, but like Creepgin said you need to update the player loop. If you look into the source you can see the call to UpdatePlayerLoop:

    Unity.Entities.Hybrid\Injection\DefaultWorldInitialization.cs
    Code (CSharp):
    1. static ScriptBehaviourManager GetOrCreateManagerAndLogException(World world, Type type)
    2. {
    3.     try
    4.     {
    5.         return world.GetOrCreateManager(type);
    6.     }
    7.     catch (Exception e)
    8.     {
    9.         Debug.LogException(e);
    10.         return null;
    11.     }
    12. }
    13.  
    14. public static void Initialize(string worldName, bool editorWorld)
    15. {
    16.     // ! Trimmed to show only key parts !
    17.     var world = new World(worldName);
    18.     World.Active = world;
    19.     var systems = GetAllSystems(WorldSystemFilterFlags.Default);
    20.    
    21.     foreach (var type in systems)
    22.     {
    23.         var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
    24.  
    25.         foreach (var g in groups)
    26.         {
    27.             var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType);
    28.             var groupSys = groupMgr as ComponentSystemGroup;
    29.  
    30.             if (groupSys != null)
    31.             {
    32.                 groupSys.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
    33.             }
    34.         }
    35.     }
    36.  
    37.     ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
    38. }
     
  4. cort_of_unity

    cort_of_unity

    Unity Technologies

    Joined:
    Aug 15, 2018
    Posts:
    98
    Unfortunately, you may be running into a known limitation of the EntityDebugger: it only lists systems that are ultimately contained in one of the top-level system groups (Initialization, Simulation, or Presentation). I will open a ticket internally to prioritize showing "orphan" systems.

    In the meantime, you may be able to work around the limitation by adding your system to a new ComponentSystemGroup (which is itself a member of one of the top-level groups), and overriding the Update() method to not actually update any of the member systems (which I assume you'd be doing manually). I believe this should list the system in the entity debugger, though I wouldn't trust its timing information.
     
    FROS7, Zaax and rigidbuddy like this.
  5. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    Thanks a lot for the help. I'll test tomorrow, didn't expect at all I had to register the engine myself, this means that I actually never seen it working and didn't notice.

    Would it be the same for a job componentsystem?
     
  6. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    @sebas77 If you just want to add it to the default SimulationSystemGroup, you can do

    Code (CSharp):
    1. var mySystem = world.GetOrCreateManager(typeof(MySystem));
    2. var simGroup = world.GetOrCreateManager<SimulationSystemGroup>()
    3. simGroup.AddSystemToUpdateList(mySystem);
    4. simGroup.SortSystemUpdateList();
    5. ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
    And yes, same for job systems. All relevant code for reference are in DefaultWorldInitialization.cs, ScriptBehaviourUpdateOrder.cs, and DefaultWorld.cs
     
    Last edited: Mar 26, 2019
    T-Zee and sebas77 like this.
  7. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    There is still something I don't get (I didn't manage to make it work), I am not using a new world, I am using the default one, do I still have to use ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); on it (I tried, OnUpdate is still not called)?
    @Creepgin last code actually made Unity hard crash!
     
    Last edited: Mar 27, 2019
  8. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    If you are using the default initialization code, then you most likely don't need to manually do UpdatePlayerLoop(). Just remove the last line. I tested the following to be working:

    Code (CSharp):
    1. var world = World.Active;
    2. var mySystem = world.GetOrCreateManager(typeof(MySystem));
    3. var simGroup = world.GetOrCreateManager<SimulationSystemGroup>();
    4. simGroup.AddSystemToUpdateList(mySystem as ComponentSystemBase);
    5. simGroup.SortSystemUpdateList();
     
    sebas77 likes this.
  9. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    I think I sort of get it, any reason why I need to sort it though?
     
  10. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World world)
    inserts the 3 default system groups into the playerloop system list. If you are doing your own world initialization, then you need to make sure to call it at the end. Ofc, you can code your own custom UpdatePlayerLoop() too, if, for example, you need to put SimulationSystemGroup into FixedUpdate.
     
  11. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    Thanks a lot. how would I customise the UpdatePlayerLoop? with SetPlayerLoop? SetPlayerLoop doesn't seem to get a world parameter, so how could I customise it just for a new world?
     
  12. cort_of_unity

    cort_of_unity

    Unity Technologies

    Joined:
    Aug 15, 2018
    Posts:
    98
    "Adding a World to the player loop" is a concept we're trying to get away from. Systems in a non-default world can be added to one of the default World's ComponentSystemGroups (or one of their sub-groups), and will subsequently be updated from there.
     
    Singtaa likes this.
  13. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    So there is no way to update the systems in a custom way? For example we want to simulate the physic multiple times in one frame, what is the best way to do that?
     
  14. cort_of_unity

    cort_of_unity

    Unity Technologies

    Joined:
    Aug 15, 2018
    Posts:
    98
    Long-term, the SimulationSystemGroup will move back to a fixed timestep by default. In the short term, anything you want to update with a fixed timestep right now will have to be ticked manually from outside a system group (such as by a MonoBehaviour's FixedUpdate() method). We have plans for a more customizable update loop with different system groups ticking at different rates, but nothing concrete I can share at the moment.
     
    FROS7 likes this.
  15. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    I actually would like to call myself explicity the update like N times in a row. We are already doing it and it works but feels hacky