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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Manually created System does not update

Discussion in 'Entity Component System' started by Elbrus, May 14, 2022.

  1. Elbrus

    Elbrus

    Joined:
    Jun 2, 2013
    Posts:
    3
    Hi,
    I have similar problem as our frind two years ago https://forum.unity.com/threads/manually-created-system-does-not-update.882085/
    I have system that work fine when its created in default way. But when I add DisableAutoCreation attribute and use World.CreateSystem - this system added to World.AllSystems list, but not added to any SystemGroup, even not in Simulation group. That's probably why its not updated.
    Fearing some complex hidden mistakes i create new test system which also work fine without DisableAutoCreation attribute.
    Code (CSharp):
    1. namespace Core.Systems.Simulation.Battle
    2. {
    3.     [DisableAutoCreation]
    4.     public partial class TestSystem : SystemBase
    5.     {
    6.         protected override void OnCreate()
    7.         {
    8.             RequireSingletonForUpdate<BattleData>();
    9.             Debug.LogError("I am created");
    10.         }
    11.  
    12.         protected override void OnUpdate()
    13.         {
    14.             Debug.LogError("I am alive");
    15.         }
    16.     }
    17. }
    And when I add DisableAutoCreation and create this system through World.CreateSystem, this sistem also added to World.AllSystems list, but not added to any SystemGroup. And also not updated.

    I also try using World.AddSystem, World.GetOrCreateSystem with expected same result.

    P.S. I need to create system by myself to be able to add readonly static struct to my system. This struct is map data so its immuatable. So I won't to add local variable and copy all this big data on each frame.
    Do you know the best way to solve this problem?
    Code (CSharp):
    1.  protected override void OnUpdate()
    2. {
    3.         var mapData = this.mapData;
    4.         // using map data in job
    5. }
     
    Last edited: May 14, 2022
    heu3becteh likes this.
  2. Anthiese

    Anthiese

    Joined:
    Oct 13, 2013
    Posts:
    72
    You could get one of the existing system groups (whichever specific one you're using) and call
    group.AddSystemToUpdateList(yourSystem)
    .
     
    Last edited: May 14, 2022
    heu3becteh and Elbrus like this.
  3. Elbrus

    Elbrus

    Joined:
    Jun 2, 2013
    Posts:
    3
    Thanks this resolve my problem.
    Very strange that i don't find mentions about requirness of this call in docs at least in chapter Worlds - Managing systems.
    Expected behaviour - i already described system group by attribute in system, so when I am creating system it whould be added to described system group byself (by World.CreateSystem)
     
    heu3becteh likes this.
  4. heu3becteh

    heu3becteh

    Joined:
    Aug 6, 2020
    Posts:
    25
    I feel that the systems with [DisableAutoCreation] should not be Auto-created, but should be Auto-updated upon creation, especially when [AlwaysUpdateSystem] is deprecated.

    By the way, I start the system with [DisableAutoCreation] in ISystem with command World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<SimulationSystemGroup>().AddSystemToUpdateList(World.DefaultGameObjectInjectionWorld.CreateSystem<YourDisableAutoCreationSystemName>());
    That way the system is created and updates in SimulationSystemGroup.