I am trying to make a terrain with 15625 blocks, and I plan to make a bigger world, so I will have much more blocks in the future. I am having a hard time trying to optimize my game so it doesn’t lag, but I cant seem to find a solution.
Heres a picture with the profiler and scene opened:
Screenshot by Lightshot
Okay where should i start? You should NOT generate your terrain using just blocks. What you need to do is generate the world out of Quads. You should only generate the quads that you are able to see. Also you should combine the meshes of your quads to single meshes (chunks) (lets say 16 blocks combined to one big mesh is one chunk). That way your terrain will be generated much much faster. I am using a voxel terrain for my current project too, so maybe i can add some screenshots later
The fastest solution is set a draw distance of your player, with SetActive(bool), it can fix the problem. The lag is caused by the 15625 box colider, physical calculations have a havy CPU usage. You can try the following code:
float distance = 1000F;
foreach (GameObject g in objects)
g.SetActive(Vector3.Distance(g.transform.position,player.transform.position) < distance);