public void Execute() { var addedEntityCount = 0; var removedEntityCount = RemovedChunkEntities.Length; for (var i = 0; i < GatheredChanges.Length; i++) { var changesForChunk = GatheredChanges[i]; addedEntityCount += changesForChunk.AddedComponentEntities.Length; removedEntityCount += changesForChunk.RemovedComponentEntities.Length; } if (addedEntityCount == 0 && removedEntityCount == 0) { return; } var buffer = new UnsafeList(UnsafeUtility.SizeOf <byte>(), UnsafeUtility.AlignOf <byte>(), (addedEntityCount + removedEntityCount) * ComponentSize, Allocator); var addedComponents = new UnsafeList(UnsafeUtility.SizeOf <Entity>(), UnsafeUtility.AlignOf <Entity>(), addedEntityCount, Allocator); var removedComponents = new UnsafeList(UnsafeUtility.SizeOf <Entity>(), UnsafeUtility.AlignOf <Entity>(), removedEntityCount, Allocator); var chunksWithRemovedData = new NativeList <int>(GatheredChanges.Length, Allocator.Temp); for (var i = 0; i < GatheredChanges.Length; i++) { var changesForChunk = GatheredChanges[i]; if (changesForChunk.AddedComponentDataBuffer.IsCreated) { buffer.AddRangeNoResize <byte>(changesForChunk.AddedComponentDataBuffer.Ptr, changesForChunk.AddedComponentDataBuffer.Length); addedComponents.AddRangeNoResize <Entity>(changesForChunk.AddedComponentEntities.Ptr, changesForChunk.AddedComponentEntities.Length); changesForChunk.AddedComponentDataBuffer.Dispose(); changesForChunk.AddedComponentEntities.Dispose(); } if (changesForChunk.RemovedComponentDataBuffer.IsCreated) { chunksWithRemovedData.AddNoResize(i); } } for (var i = 0; i < chunksWithRemovedData.Length; i++) { var changesForChunk = GatheredChanges[chunksWithRemovedData[i]]; buffer.AddRangeNoResize <byte>(changesForChunk.RemovedComponentDataBuffer.Ptr, changesForChunk.RemovedComponentDataBuffer.Length); removedComponents.AddRangeNoResize <Entity>(changesForChunk.RemovedComponentEntities.Ptr, changesForChunk.RemovedComponentEntities.Length); changesForChunk.RemovedComponentDataBuffer.Dispose(); changesForChunk.RemovedComponentEntities.Dispose(); } chunksWithRemovedData.Dispose(); buffer.AddRangeNoResize <byte>(RemovedChunkComponentDataBuffer.GetUnsafeReadOnlyPtr(), RemovedChunkComponentDataBuffer.Length); removedComponents.AddRangeNoResize <Entity>(RemovedChunkEntities.GetUnsafeReadOnlyPtr(), RemovedChunkEntities.Length); Result.Value = new Result { Buffer = buffer, AddedComponents = addedComponents, RemovedComponents = removedComponents }; }