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. - 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?