Hi all so i was making my voxel engine ,its a multi-threaded engine , i get the players position through Update , store it then check if a chunk is a certain distance away from the player , then i deleete it,Now I noticed something odd , if i travel from the centre of the world outwards for some reason the engine starts unloading chunks right below me , so either the vector2 class is no longer thread safe and unity forgot to add a warning or theres a bug in unity somewhere , its not in the position system , cause when i debug it everything is correct , i’m wondering if maybe there is an error in the distance class maybe or something , my distance checking is quite simple its just if(Vector2.Distance(PlayerPos, chunkPos )>DistanceToload){
unloadchunk}
Any ideas would be extremely helpful as i’ve tried my hardest to fix the problem (been at it for a day now).
void checkActiveChunks(){
if(ActiveChunks.Count>0){
for(int i = 0;i < ActiveChunks.Count;i++){
VoxelChunk chunk = ActiveChunks[i];
Vector2 chunkpos = new Vector2(chunk.m_pos.x ,chunk.m_pos.z)/TriSize[chunk.lodLevel];
Vector2 playerpos = new Vector2(ChunkPosition.x,ChunkPosition.z);
if(Vector2.Distance(chunkpos,playerpos)>=distanceToLoad+25){
if(chunk.HasChanged && chunk.shouldrender)
chunk.SaveVoxels();
Trash.Add(chunk);
m_voxelChunk.Remove((int)(chunk.RealPos.x),(int)(chunk.RealPos.z));
if(ActiveChunks.Contains(chunk)){
GrassChunks.Remove(chunk);
ActiveChunks.Remove(chunk);
}
return;
}
}
}
}
Full code if it helps