Doing this over and over in a system:
for (var i = 0; i < Size * Size; i++) {
var shouldBeShown = i < _index || i >= _index + _range * 2;
var isShown = !SystemAPI.HasComponent<DisableRendering>(_entities[i]);
if (shouldBeShown == isShown) continue;
if (shouldBeShown) {
state.EntityManager.RemoveComponent<DisableRendering>(_entities[i]);
} else {
state.EntityManager.AddComponent<DisableRendering>(_entities[i]);
}
}
_index += _range;
Causes the chunks to fragment by a lot. The lower the range variable is, the more they fragment. I've tested both with AddComponent/RemoveComponent, EntityCommandBuffer (one at a time), and AddComponent/RemoveComponent with an array of all entities that should change that frame, and all have the same result.
Is there a good way of doing structural changes that prevents fragmentation?