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

DOTS Editor Systems window isn't showing any systems in my custom off-main-thread world

Discussion in 'Entity Component System' started by bilalakil, Feb 9, 2022.

  1. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    Unity 2021.2.7f1; Unity.Entities 0.17.0-preview.42; Unity.DOTS Editor 0.12.0-preview.6. I'm working on a game where I run a separate thread to handle all match state processing, because rendering is really slow here and I want to avoid as much main-thread activity as possible. I create an ECS World in the main thread, and then loop in a separate thread to `SetTime` and `Update` it manually.

    When the world is running, it appears in the Systems and Entities editor tabs / windows' world selection dropdowns. The Entities window successfully shows all entities and their components as they appear. However, the Systems window shows the world as though it has no systems at all. If I change it to Show Full Player Loop then I can see all of the basic player loop systems, so it seems that only my world is being affected.

    I've subclassed `World` and add systems to it in the constructor. It's being instantiated on the main thread. This is what the constructor looks like:

    Code (CSharp):
    1.     public class MatchStateProcessorWorld : World
    2.     {
    3.         public MatchStateProcessorWorld(MatchState initialState) : base("FrankenStorm Match State Processor World")
    4.         {
    5.             var delta = initialState.time == 0 ? 0f : (float)MatchStateProcessor.TICK_TIME;
    6.             SetTime(new Unity.Core.TimeData(initialState.time, delta));
    7.  
    8.             var sysGroup = CreateSystem<SimulationSystemGroup>();
    9.             sysGroup.AddSystemToUpdateList(CreateSystem<SpawnSystem>());
    10.         }
    11.     }
    Is there something else I need to do to have these systems appear in the editor window, or is there something wrong with my approach here?
     
  2. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    An unfortunate update on this sitch: there were other instabilities and frequent crashes occurring, with mostly incomprehensible (by me at least) logs. I tried removing the DOTS Editor package and then things smoothed out nicely. So I'll be leaving it off for a while - seems like this package assumes main-thread operation for now?
     
  3. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    Hmm unfortunately I'll be giving up on running the world from another thread Lots of problems where things in the Entities package are hardcoded to use `Allocator.Temp` which doesn't work, see this error:

    ArgumentException: Could not allocate native memory. If this allocation was made from a managed thread outside of a job, you must use Allocator.Persistent or Allocator.TempJob.


    e.g. even using `EntityCommandBuffer`s has this occur.
     
  4. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    Curiously this problem is still occurring with everything moved back onto the main thread. I am still using a custom world though, not the ones Unity bootstraps itself, as I've got save/load functionality hooked up nice and easily this way.

    I wonder what I'm missing o_O
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    It's been a while since I look at the reasoning but if I recall either you need to force add it to the playerloop or maybe even only updates from the default world will appear in here.

    The trick that packages like netcode and we use at work is we update custom worlds from a system in the default world - this causes everything to appear nicely in the inspector.
     
  6. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    Ohhh interesting! So the two worlds exist beside each other, you write systems which are automatically hooked up to the default world, and in those systems you explicitly reference your IndependentWorld.EntityManager and such instead of what the system would've defaulted to?
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    No. You just create 2+ worlds but you simply call World2 [InitializationSystemGroup|SimulationSystemGroup|PresentationSystemGroup].Update from a system in World1
     
    bilalakil likes this.
  8. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    So im trying to achieve this on the new 1.0 version, but it doesnt work.
    I create a emtpy world in bootstrap with my "worldupdater" system and append this world to the playerloop like normal.
    I then create a new world in the worldupdater.oncreate, and do world.update in its onupdate.

    The systemswindow shows my world as completely empty however.
    (it does give nice info about the default world though, the one with only 1 system)

    So it looks like:
    • Defaultworld
      • Simulationgroup
        • MyVariablerategroup
          • MyWorldSystem (this owns the world im interested in)
            • MyWorld.Update() (this world actually contains the logic i want to see in the editor)
    If this is no longer possible with this method, is there any other way to make the editors work with custom stepped worlds?
     
  9. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    127
    In this thread you see a simple ICustomBootstrap that results in both worlds nicely showing all added systems in the editor (Systems Window). The important call for that is
    Code (CSharp):
    1. ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(anotherWorld);
    The issue I am having is that all Singletons providing access to the unmanaged EntityCommandBufferSystems end up in the Default World, and not in world I like to have them in....
     
    Last edited: Oct 4, 2022
    bilalakil likes this.