Search Unity

Entities 0.9.1 Deprecated CreateSystem / AddSystem and OnCreate Order issues

Discussion in 'Entity Component System' started by Ziboo, Apr 17, 2020.

  1. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Hello,

    I just updated to the latest version of Entities 0.9.1.
    I have issue with a setup that I used before.

    Here is my groups setup:
    Code (CSharp):
    1.  
    2.     public class FactorySpawnGroup : FactoryGroupBase
    3.     {
    4.      
    5.     }
    6.  
    7.     public class FactoryActionGroup : FactoryGroupBase
    8.     {
    9.      
    10.     }
    11.    
    12.     [UpdateBefore(typeof(TransformSystemGroup))]
    13.     public class FactoryGroup : ComponentSystemGroup
    14.     {
    15.         public static int FixedUpdateRate = 60;
    16.     }
    17.    
    18.     [DisableAutoCreation]
    19.     public class FactoryCommandBuffer : EntityCommandBufferSystem
    20.     {
    21.        
    22.     }
    23.     [DisableAutoCreation]
    24.     public class FactoryNewEventSystem : EventSystem
    25.     {
    26.  
    27.     }
    28.    
    29.  
    30.     [UpdateInGroup(typeof(FactoryGroup))]
    31.     [AlwaysUpdateSystem]
    32.    
    33.     public abstract class FactoryGroupBase : ComponentSystemGroup
    34.     {
    35.         private FactoryCommandBuffer endBufferSystem;
    36.         private FactoryNewEventSystem newEventSystem;
    37.  
    38.         public FactoryCommandBuffer EndBufferSystem
    39.         {
    40.             get { return this.endBufferSystem; }
    41.         }
    42.  
    43.         public FactoryNewEventSystem NewEventSystem
    44.         {
    45.             get { return this.newEventSystem; }
    46.         }
    47.  
    48.  
    49.         protected override void OnUpdate()
    50.         {
    51.             base.OnUpdate();
    52.        
    53.             this.endBufferSystem.Update();
    54.             this.newEventSystem.Update();
    55.         }
    56.         protected override void OnCreate()
    57.         {
    58.             base.OnCreate();
    59.             this.endBufferSystem = World.CreateSystem<FactoryCommandBuffer>();
    60.             this.newEventSystem = World.CreateSystem<FactoryNewEventSystem>();
    61.         }
    62.     }
    And a sample System that use it:
    Code (CSharp):
    1. [UpdateInGroup(typeof(FactorySpawnGroup))]
    2. public class FactorySpawnEventSystem : SystemBase
    3. {
    4.     private FactoryCommandBuffer bufferSystem;
    5.     private FactoryNewEventSystem eventSystem;
    6.  
    7.      protected override void OnCreate()
    8.     {
    9.         this.eventSystem = this.World.GetExistingSystem<FactorySpawnGroup>().NewEventSystem;
    10.         this.bufferSystem = this.World.GetExistingSystem<FactorySpawnGroup>().EndBufferSystem;
    11.     }
    12. }
    So everything worked fine before the update.

    AddSystem issue:

    Now if I want to replace
    this.endBufferSystem = World.CreateSystem<FactoryCommandBuffer>();

    by
    this.endBufferSystem = World.AddSystem(new FactoryCommandBuffer());


    it will throw an error World.cs -> line 373

    if (GetExistingSystemInternal(system.GetType()) != null)
    throw new Exception($"Attempting to add system '{TypeManager.GetSystemName(system.GetType())}' which has already been added to world '{Name}'");


    Since I have multiple Factory Group, it sees that the system already exists, but not really because it's contained in each class...

    Create System Order issue:

    this.eventSystem = this.World.GetExistingSystem<FactorySpawnGroup>().NewEventSystem;


    This was working fine before but now return null.
    For what I debugged, OnCreate is called on every systems and after on Groups.
    Which I think is backward, Groups should be initialized, then the systems.

    Any though ? Is all of that intended ?
    Because if I want to update I pretty much need to rethink my all architecture.

    Thanks
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Not the exact same issue but this change bit us also. We were calling GetOrCreateSystem from OnCreate which previously resulted in the OnCreate of the other system being run immediately. GetOrCreateSystem should run OnCreate immediately or it's basically worthless.