Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple worlds - Any easy way to call all the default systems in correct order?

Discussion in 'Entity Component System' started by PixelMind, Dec 7, 2018.

  1. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    I'm trying to run two ecs worlds on one game instance. I figured that I have to create worlds and then call Update() manually on each system. However now that I'm running everything manually, I also seem to lose the default systems running behind the default World. So systems like TransformSystem and MeshInstanceRendererSystem are not updated. Also systems are not visible on entity debugger window when they are updated manually.

    Is there a way to call these "essential" systems automatically? Or hook my worlds to update just like the default world? There's World.Active but that's for a single world.
    Any pointers how this might be best to implement would be appreaciated :)

    Right now I can only think of just going through the codebase and try to figure out when each default system should be run. I have a feeling that this is bound to cause weird bugs if I forget to run something essential. Or if I just run things in wrong order. Especially as the codebase and workflow in general is new to me.

    ----

    To give some context I have a multiplayer game that has completely separated client and server logic running on editor. Physics are separate, packets are sent and received from/to the same machine, etc.
    The point is that I don't have to make a build to run client and server separately which takes ages on HDRP. Separate ECS worlds would keep entities isolated from each other.
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    You must update ScriptBehaviourUpdateOrder, for default\specific world, or for all worlds:
    ScriptBehaviourUpdateOrder.UpdatePlayerLoop(params World[]);
     
    Last edited: Dec 7, 2018
    rigidbuddy likes this.
  3. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    @eizenhorn Excellent, thank you! That was exactly what I was looking for :)

    That also fixed the issue of systems not showing up on debugger.

    ---
    Edit: or maybe not exactly. Default systems still missing... but it could well be a bug on my end.

    Edit2: So yea it did fix the issue. Just had to call CreateManager somewhere for each system which of course makes sense. It's actually better than I wanted since I can disable rendering related systems on server so I can't even accidentally run them there.
     
    Last edited: Dec 7, 2018
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    You use UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP ?

    Show you code where you create second world and update behaviour.
     
  5. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    Not at the moment but I may disable it in the future.
    But the previous edit was just an issue that I removed punch of code and forgot to create related managers. Everything renders / works correctly now and I can disable default stuff on server which is nice.

    Thanks again @eizenhorn