I’m destroying some entities via a MonoBehaviour class using EntityManager but I keep getting this error:
InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) <0x4ac1a530 + 0x00052> in <2f14d49edc704940aee557642343f344>:0
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at C:/buildslave/unity/build/Runtime/Export/AtomicSafetyHandle.bindings.cs:143)
Unity.Entities.ArchetypeChunk.GetNativeArray (Unity.Entities.ArchetypeChunkEntityType archetypeChunkEntityType) (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/Iterators/ArchetypeChunkArray.cs:63)
Unity.Transforms.TransformSystem.UpdateFrozen () (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Transforms/TransformSystem.cs:320)
Unity.Transforms.TransformSystem.OnUpdate (Unity.Jobs.JobHandle inputDeps) (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Transforms/TransformSystem.cs:1178)
Unity.Entities.JobComponentSystem.InternalUpdate () (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/ComponentSystem.cs:508)
Unity.Entities.ScriptBehaviourManager.Update () (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/ScriptBehaviourManager.cs:77)
Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelagateWrapper.TriggerUpdate () (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/ScriptBehaviourUpdateOrder.cs:703)
I figured that since I’ve disrupted the arrays by destroying an entity using EntityManager, the ECS context doesn’t like this. I tried using a system’s PostUpdateCommand. I got an instance of the system using World.GetOrCreateManager(). On the call to EntityCommandBuffer.DestroyEntity(), I got the following error:
InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) <0x505961b0 + 0x00052> in <2f14d49edc704940aee557642343f344>:0
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at C:/buildslave/unity/build/Runtime/Export/AtomicSafetyHandle.bindings.cs:153)
Unity.Entities.EntityCommandBuffer.EnforceSingleThreadOwnership () (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/EntityCommandBuffer.cs:556)
Unity.Entities.EntityCommandBuffer.DestroyEntity (Unity.Entities.Entity e) (at C:/Users/Marnel/AppData/Local/Unity/cache/packages/staging-packages.unity.com/com.unity.entities@0.0.12-preview.21/Unity.Entities/EntityCommandBuffer.cs:684)
I’m stuck. What are my other options?