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

Can you move a group of entities between worlds and keep entity references between them intact?

Discussion in 'Entity Component System' started by Zec_, Dec 2, 2019.

  1. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    I've been playing around a bit with having multiple worlds where I load, set up and initialize entities in one world and then move them to a destination world once they're ready. I've currently stumbled upon the issue where entities that point to each other get faulty entity references upon moving them.

    So my question therefore is: If I've got entities with unknown and arbitrary components that contains references to each other, is there a recommended or perhaps already existing way to get these references updated properly when I move the entities with the EntityManager.MoveEntitiesFrom-function?

    I've seen a bunch of internal code related to entity remapping and watched the Unite talk regarding it, but haven't really understood how to use the functionality, or if it's even intended for these kinds of applications. Does anyone have any guidance on the subject?
     
    FlightFight likes this.
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    MoveEntitiesFrom remaps entity references.
     
    Zec_ likes this.
  3. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    Thanks for the quick response and the clarification. I'll investigate further, as I seem to be having some issues with this. Is this supposed to cover all component types? I seem to have issues with ISharedComponents that contain entity references specifically. Their references doesn't seem to get updated when moved.

    I just now tried making an ISharedComponentData and a regular IComponentData and set their values to point at the same entity, but after move only the IComponentData points correctly and the ISharedComponentData points at the same ID as before the move.

    I can set up an example project and report it as a bug tomorrow if it's intended to work.
     
  4. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    274
    FYI: MoveEntitiesFrom still does not support ISharedComponentData with Entity references.
     
    FlightFight likes this.