Search Unity

How to update new World

Discussion in 'Entity Component System' started by povstalez_unity, Oct 18, 2019.

  1. povstalez_unity

    povstalez_unity

    Joined:
    Nov 18, 2017
    Posts:
    4
    Hi, sorry for my bad english.

    I'm disable auto bootstrap and create new world:

    Code (CSharp):
    1.  
    2. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    3.     static void Init()
    4.     {
    5.         World myWolrd = new World("tewst world");
    6.         World.Active = myWolrd;
    7.         manager = World.Active.GetOrCreateSystem<EntityManager>();
    8.         World.Active.GetOrCreateSystem<CoinsIncrementJobSystem>();
    9.     }
    10.  
    But my "CoinsIncrementJobSystem" don't update.

    What I need to do for my "CoinsIncrementJobSystem" update automaticly?

    And second question:

    How disable auto creation system in default world on startup, and add this system in any time, when I needed?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Your systems should be in player loop, for player loop there is should be 3 root groups - Initialization, Simulation, Presentation, and your system should be inside one of this group.
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Jobs;
    3. using UnityEngine;
    4.  
    5. public class WithoutDefaultWorld
    6. {
    7.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    8.     static void RunSystems()
    9.     {
    10.         Debug.Log("I'm tired, let's create better world!");
    11.         var world = new World("New Better World");
    12.         World.Active = world;
    13.        
    14.         PlayerLoopManager.RegisterDomainUnload (DomainUnloadShutdown, 10000);
    15.        
    16.         var initGroup = world.CreateSystem<InitializationSystemGroup>();
    17.         var simGroup = world.CreateSystem<SimulationSystemGroup>();
    18.         var presGroup = world.CreateSystem<PresentationSystemGroup>();
    19.        
    20.         var superSystem = world.CreateSystem<MysSuperSystem>();
    21.         simGroup.AddSystemToUpdateList(superSystem);
    22.         simGroup.SortSystemUpdateList();
    23.        
    24.         ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
    25.     }
    26.    
    27.     static void DomainUnloadShutdown()
    28.     {
    29.         World.DisposeAllWorlds();
    30.         ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.Active);
    31.     }
    32. }
    33.  
    34. public class MysSuperSystem : JobComponentSystem
    35. {
    36.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    37.     {
    38.         Debug.Log("Super Update!");
    39.         return inputDeps;
    40.     }
    41. }
    upload_2019-10-18_9-59-12.png
     
    andrew-lukasik likes this.