Efficient access to Mesh arrays

I posted this question on Unity Answers but I feel it’s more suitable for the technical forums, so re-posting.

I am using SkinnedMeshRenderer.BakeMesh every frame and then retrieving the arrays of vertices, triangles, normals etc. for further processing.

The problem is that Unity’s implementation of these property getters creates a new array every single call, rather than updating an existing one and returning it, and that leads to unnecessary object allocation and frequent GC spikes.

A few implementations that could have solved the problem, had they existed:

  • Mesh.GetVertex(int index), Mesh.GetTriangle(int index), etc. - could provide direct access to an array member
  • Mesh.GetVertices(ref float[ ] outputArray), etc. - could perform an array copy instead of a new array allocation

Are there any actual ways to access this data without the GC overhead?

It’s on our roadmap but not available now, sorry!

Okay, thanks! A bit of a bummer, that. Makes BakeMesh a bit useless for realtime operations. I’m afraid I might have to resort to pre-baking the meshes at a low FPS and using that for lookup.

Since we’re on the subject of array handling in Unity, there are many methods and properties in the Unity API that return arrays, so it might be a smart move to either cache the array object as long its length doesn’t change, or simply add versions of those methods that accept an input array for copying, as I suggested in my post.

Im searhing for this too , any update ?

Any update on this? Is this possible yet, or is there an ETA for it?