In my DOTS game, I have a debug function where when I hit the spacebar I wipe all entities in the world, and restart the systems. This “reset” system is the final system that runs within the frame.
Oddly, this occasionally has a knock-on effect where GetAllUniqueSharedComponentsManaged() and GetSharedComponentIndex() can sometimes return different values.
This is illustrated within the below code which occasionally hits the Debug.Break();, and from my understanding of those APIs that shouldn’t be possible?
List<RendererComponent> uniqueRenderers = new List<RendererComponent>()
EntityManager.GetAllUniqueSharedComponentsManaged(uniqueRenderers);
foreach (var (myComponent, entity) in SystemAPI.Query<RefRO<MyComponent>>().WithEntityAccess())
{
var chunk = EntityManager.GetChunk(entity);
int index1 = chunk.GetSharedComponentIndex(GetSharedComponentTypeHandle<RendererComponent>());
int index2 = uniqueRenderers.IndexOf(EntityManager.GetSharedComponentManaged<RendererComponent>(entity));
//(I've done a count, uniqueRenderers definitely only contains one copy!)
if(index1 != index2)
Debug.Break();
}
Does anyone have any insight into under what circumstances this might happen so I can narrow this down?