I am new to Unity and me and have run into a problem that I can't solve.
I am generating my games terrain procedurally, and storing the meshes for the terrain in several different game objects. I don't use one big mesh because I want to be able to quickly update one part of the mesh at runtime.
I am reusing gameobjects to hold new terrain as you move through the world and I repopulate their meshes with this code:
Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Clear(); mesh.vertices = vertArr; mesh.normals = normArr; mesh.uv = texArr; mesh.triangles = indArr; mesh.RecalculateNormals(); mesh.RecalculateBounds();
This works well, but uses more memory every time I redo the mesh. Looking at the stats window it seems that my VBO total and the ram associated with it is probably the culprit. Looking at the profiler, my mesh number is always the same but the mesh memory increases with the VBO memory.
Is there anyway to get around this? Is assigning mesh.vertices several times just a bad idea?
Thanks for your help!
UPDATE: I followed Jesse's advice and switched to using sharedMesh. It solved my high VBO count problem, but VBO memory still seems to be an issue.