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.

Resolved [1.0.0-exp.8]: EntityCommandBufferSystem.Singleton and ICustomBootstrap - HOW?

Discussion in 'Entity Component System' started by Fribur, Oct 3, 2022.

  1. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    125
    Got a very simple ICustomBootstrap and cannot figure out how the get the EntityCommandBufferSystem Singletons into the second world: as you can see in the picture: one world has two Singletons, and the other zero. Obviously the call to SystemAPI.GetSingleton<Any EntityCommandBufferSystem.Singleton>() fails in both world as a consequence of that. Stupid mistake on my end or bug in Entities [1.0.0-exp.8]?
    upload_2022-10-3_13-0-22.png
    Code (CSharp):
    1. public class LoadingWorldBootStrap : ICustomBootstrap
    2. {
    3.     public bool Initialize(string defaultWorldName)
    4.     {
    5.         World.DefaultGameObjectInjectionWorld = new World("My Default World");
    6.         var anotherWorld = new World("AnotherWorld");
    7.  
    8.  
    9.         var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
    10.         DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(World.DefaultGameObjectInjectionWorld, systems);
    11.         ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(World.DefaultGameObjectInjectionWorld);
    12.  
    13.         DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(anotherWorld, systems);
    14.         ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(anotherWorld);
    15.         return true;
    16.     }
    17. }
     
    Last edited: Oct 4, 2022
  2. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    125
    Never mind. Turns out everything was just fine and the issue above was a stupid mistake on my end after all. The following innocuous little line moved ALL entities from "anotherWorld" (which I use as a loading/staging World) to the Default World, INLCUDING the ECB singleton.
    Code (CSharp):
    1. _entityManager.MoveEntitiesFrom(anotherWorldEntityManager);
    Which of course leads to a duplication of the ECB Singleton in the Default world, and 0 Singletons in "anotherWorld"