//threaded chunk generation with debugging if theres an error void GenerateChunks() { while (CanContinue) { try { if (RequestedChunks.Count > 0) { //Create the voxel data Vector2 ppos = new Vector2(Player.x, Player.z); //order the chunks before creation so that oonly chunks closest to player get created first //had to copy to another array before ordering as it caused errors otherwise RequestedChunksOrdered = RequestedChunks.ToList(); RequestedChunksOrdered = RequestedChunksOrdered.OrderBy (C => Vector2.Distance(ppos, new Vector2(C.m_pos.x, C.m_pos.z))).ToList(); //use first chunk in the orderered list to create meshes VoxelChunk chunk = RequestedChunksOrdered[0]; //createmeshes using voxel data chunk.CreateMeshesAndvoxels(true); //add to active chunks list ActiveChunks.Add(chunk); //remove chunk from list so ass to not create again RequestedChunks.Remove(chunk); } //sleep thread if no chunks to create else { Thread.Sleep(5); } //catch all exceptions and display message in console } catch (Exception e) { Debug.LogError(e.StackTrace + e.Message); } } }