Hello !
I am working on a procedural planet generator for a school project. So for the dynamic LOD I create meshes in run-time.
However I have some functions that need to access the data contained in the terrain meshes, like the height of the vertices or the normals to calculate the slope. As that data is only stored in the mesh (keeping it in other arrays would double the memory usage, I’m trying to be as efficient as possible) to access it I was always using meshFilter.mesh.vertices[ ] or meshFilter.mesh.normals[ ].
But then I read something here about how when one does this, Unity creates a copy of the entire array each time you call it. I guess it’s a security of some sort but here I’m only reading data, not writing in it, so it seems like a waste of performance.
I tried using sharedMesh instead (so the call is meshFilter.sharedMesh.vertices[ ]) but it takes the same amount of time to execute the code, so I guess it’s not different ?
TL-DR : So my question is does Unity really make a copy of the mesh arrays each time you access it even with sharedMesh, and if yes is there a way to avoid it without storing it somewhere else ?
Thanks for your time