Search Unity

GameObjects and Multiple ECS worlds

Discussion in 'Entity Component System' started by CPlusSharp22, Aug 20, 2020.

  1. CPlusSharp22

    CPlusSharp22

    Joined:
    Dec 1, 2012
    Posts:
    111
    Im currently trying to handle multiple ECS worlds and multiple game objects that have entities that relate to them. I'm going to have multiple worlds, and the gameobjects exist across them. The "active" world is the one that controls the gameobject.

    I'm thinking that the best way is to switch from having 1 entity reference on each gameobject to having multiple ones, one for each world. And whatever world is "active", the entity for that world is the "active" entity. And perhaps I tie some state recording into it as well, like was the gameobject enabled or disabled in that world, and restore the state when the active world and entity switches.

    Does this sound like a sane thing to do? I'm trying to think of alternatives but that seems like the most appropriate way forward. Right now, the conversion system only allows one World to have a GameObject, but if I leverage the `CopyEntitiesFrom` API on the EntityManager I think I can make it work.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    i guess the question i have that would change how i'd respond is, why the multiple worlds?
     
  3. CPlusSharp22

    CPlusSharp22

    Joined:
    Dec 1, 2012
    Posts:
    111
    Running multiple simulations. One is hidden while the other one is active, but it still needs to run in the background. A third world for replays, rewinding, debug, etc
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    So how do the game objects tie in? Is it your presentation and you want to use between the worlds?
     
  5. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    I did something similar before for prototyping a little time travel concept. Converted everything into a default world, then copied the initial state/data of all entities into a duplicate world.

    Game object and hybrid renderer presentation would run off the present world. If there was a time travel operation that would affect the past I would inject the time alteration into an alternative world that is running say 10 seconds in the past behind the present world and then execute it's simulation several times per frame to catch it up with the current. Then I'd swap the worlds - and the presentation would now run off the past (now current) world.

    So yea it's possible to do it the way you describe I think.
     
    Last edited: Aug 20, 2020
    CPlusSharp22 likes this.
  6. CPlusSharp22

    CPlusSharp22

    Joined:
    Dec 1, 2012
    Posts:
    111
    Thanks, yep that's kind of exactly what I'm going for.