This block in Chunk.cs public void GenerateChunkMesh should be moved into Awake and replaced with List.Clear() calls.
verts = new List<Vector3>(98304);
tris = new List<int>(147456);
uvs = new List<Vector2>(98304);
coloruvs = new List<Vector2>(98304);
Store chunks in a Dictionary in World.cs. An Array[,,] will not work for infinite terrain.
When chunks are unloaded, make sure to collect Mesh and Material instances that have been created. Either by Destroy() or by reusing them.
In general, carefully consider any new calls for class instances, try to reduce these instances as much as possible.
This block in Chunk.cs
public void GenerateChunkMeshshould be moved intoAwakeand replaced with List.Clear() calls.Store chunks in a Dictionary in World.cs. An Array[,,] will not work for infinite terrain.
When chunks are unloaded, make sure to collect Mesh and Material instances that have been created. Either by Destroy() or by reusing them.
In general, carefully consider any
newcalls forclassinstances, try to reduce these instances as much as possible.