I’m discovered a strange behaviour after destroying entities from native list. In my game I’m add all entities, which needs to be destroed to native list and call EntityManager.DestroyEntity(DestroyEntitiesList) from DestroySystem. If destroyed entities have managed component, I can access some component from another exists entity in same chunk.
Simple example:
entity0: MyMonoBehaviour with id = 1 (destroing frame = 1)
entity1: MyMonoBehaviour with id = 2 (destroing frame = 1)
entity2: MyMonoBehaviour with id = 3 (destroing frame = 3)
Entities.ForEach((Entity e, MyMonoBehaviour monoBeh, ref DestructionTime frame) =>
{
if (frame.Value != Time.frameCount) return;
_destroySystem.DestroyEntitiesList.Add(e);
Debug.Log($"{Time.frameCount} frame: Destroy entity index={e.Index} with component id={monoBeh.Id}, already destroyed={monoBeh == null}");
Object.Destroy(monoBeh.gameObject);
});
entity0 and entity1 were destroyed at 1 frame, after entity2 has a link to the mono component from entity1 that has already been destroyed.