Search Unity

MoveEntitiesFrom always fails with shared components

Discussion in 'Entity Component System' started by b2937, Jul 1, 2019.

  1. b2937

    b2937

    Joined:
    Jul 1, 2019
    Posts:
    13
    Hello

    While working on World serialize/deserialize, I ended up with something mostly working except the call to EntityManager.MoveEntitiesFrom throwing this exception:

    Code (plain):
    1. EntityManager.MoveEntitiesFrom failed - All ISharedComponentData references must be from EntityManager. (For example EntityQuery.SetFilter with a shared component type is not allowed during EntityManager.MoveEntitiesFrom)

    Looking into it, it seems that the internal function ManagedComponentStore.AllSharedComponentReferencesAreFromChunks always returns false when there are any shared components. This can easily be confirmed by adding this line of code into the OnUpdate of a system:

    Code (CSharp):
    1. new EntityManager.EntityManagerDebug(EntityManager).CheckInternalConsistency();
    I tried this in our project, in Boids from EntityComponentSystemSamples and in CombatBees from DOTS-training-samples. All resulted with the exception below:

    Code (plain):
    1. Assertion failure. Value was False
    2.  
    3. Expected: True
    4. 0x000002EE2CC2998B (Mono JIT Code) [Assert.cs:15] Unity.Assertions.Assert:IsTrue (bool)
    5. 0x000002EE4CF67663 (Mono JIT Code) [EntityManagerDebug.cs:240] Unity.Entities.EntityManager/EntityManagerDebug:CheckInternalConsistency ()
    6. 0x000002EE4CF66EA3 (Mono JIT Code) [SomeSystem.cs] SomeSystem:OnUpdate ()
    7. 0x000002EE4CF09E8B (Mono JIT Code) [ComponentSystem.cs:818] Unity.Entities.ComponentSystem:InternalUpdate ()
    Tested in 2019.1.8f1 with Entities preview.33 - 0.0.12.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    This doesn't surprise me. The scd indices won't match between worlds.
     
  3. b2937

    b2937

    Joined:
    Jul 1, 2019
    Posts:
    13
    So the thing is it fails that assert even before attempting any serialization/deserialization by just calling CheckInternalConsistency in OnUpdate. It's as if having any shared component makes the world inconsistent, which makes no sense.

    Also deserialization with the shared component ended up working fine when I commented out that assertion inside MoveEntitiesFrom. But our project only has very few shared components (similar to Boids) so maybe it's just luck for now. There seems to be plenty of code in the serialize/deserialize functionality to handle that though.