public void Execute(Entity entity, int index, [ReadOnly] ref Spawner spawnerFromEntity, [ReadOnly] ref LocalToWorld location) { var parent = spawnerFromEntity.Parent; var horizontalInterval = spawnerFromEntity.HorizontalInterval; var verticalInterval = spawnerFromEntity.VerticalInterval; var depthInterval = spawnerFromEntity.DepthInterval; var origin = parent != Entity.Null ? LocalToWorldFromEntity[parent].Value : location.Value; for (var x = 0; x < spawnerFromEntity.CountX; x++) { for (var y = 0; y < spawnerFromEntity.CountY; y++) { for (var z = 0; z < spawnerFromEntity.CountZ; z++) { // Place the instantiated in a grid var instance = CommandBuffer.Instantiate(index, spawnerFromEntity.Prefab); var position = math.transform( origin, new float3((x - spawnerFromEntity.CountX * 0.5f) * horizontalInterval, (y - spawnerFromEntity.CountY * 0.5f) * verticalInterval, (z - spawnerFromEntity.CountZ * 0.5f) * depthInterval)); CommandBuffer.SetComponent(index, instance, new Translation { Value = position }); if (parent != Entity.Null) { CommandBuffer.SetParent(index, parent, instance); } } } } CommandBuffer.DestroyEntity(index, entity); }