private void MoveAggregatedVoxelsIntoNewContainers(object aBuildTask) { PhysicsBuildTask buildTask = (PhysicsBuildTask)aBuildTask; int gameObjectIndex = 0; try { if (buildTask.physicsAggregatedList != null) { while (buildTask.physicsAggregatedList.Count > 1) { int smallestIndex = 0; VoxelContainer newContainer = buildTask.voxelContainerList[gameObjectIndex]; newContainer.AssignUVDictionary(this.container); foreach (Voxel curVoxel in buildTask.physicsAggregatedList[smallestIndex]) { newContainer.AddVoxel(curVoxel, true); lock (this.container.voxels) { this.container.RemoveVoxel(curVoxel, true); } } Texture2D curTexture = null; int curTextureWidth = 0; int curTextureHeight = 0; foreach (VoxelArea curArea in this.container.voxelAreas.Values) { curTexture = curArea.GetTexture(); curTextureWidth = curArea.GetTextureWidth(); curTextureHeight = curArea.GetTextureHeight(); if (curTexture != null) { break; } } foreach (VoxelArea curArea in newContainer.voxelAreas.Values) { curArea.SetTexture(curTexture, curTextureWidth, curTextureHeight); } foreach (VoxelArea curArea in newContainer.voxelAreas.Values) { curArea.SetTexture(curTexture, curTextureWidth, curTextureHeight); } newContainer.GenerateAreaBuffers(); newContainer.rebuildCollider = false; List <VoxelContainer.ColliderDescriptor> colliders = newContainer.PrepareColliderDescriptors(); buildTask.colliders.Add(colliders); gameObjectIndex++; buildTask.physicsAggregatedList.RemoveAt(smallestIndex); } buildTask.mainBodyCollider = this.container.PrepareColliderDescriptors(); lock (this.container.voxels) { this.container.rebuildCollider = false; this.container.GenerateAreaBuffers(); this.container.mustRebuildBeforeUpdate = false; this.container.ingameBuildTask = null; } this.currentState = PhysicsState.Finalisation; buildTask.isReady = true; } } catch (Exception e) { Debug.LogError("VoxelPhysics error: " + e.Message); } }