MoveEntitiesFrom always fails with shared components

Hello

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

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:

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:

Assertion failure. Value was False

Expected: True
…
0x000002EE2CC2998B (Mono JIT Code) [Assert.cs:15] Unity.Assertions.Assert:IsTrue (bool)
0x000002EE4CF67663 (Mono JIT Code) [EntityManagerDebug.cs:240] Unity.Entities.EntityManager/EntityManagerDebug:CheckInternalConsistency ()
0x000002EE4CF66EA3 (Mono JIT Code) [SomeSystem.cs] SomeSystem:OnUpdate ()
0x000002EE4CF09E8B (Mono JIT Code) [ComponentSystem.cs:818] Unity.Entities.ComponentSystem:InternalUpdate ()
…

Tested in 2019.1.8f1 with Entities preview.33 - 0.0.12.

This doesn’t surprise me. The scd indices won’t match between worlds.

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.