Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Efficient access to Mesh arrays

Discussion in 'Editor & General Support' started by daterre, Jun 2, 2014.

  1. daterre

    daterre

    Joined:
    Jul 30, 2012
    Posts:
    41
    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?
     
  2. Kaspar-Daugaard

    Kaspar-Daugaard

    Unity Technologies

    Joined:
    Jan 3, 2011
    Posts:
    150
    It's on our roadmap but not available now, sorry!
     
  3. daterre

    daterre

    Joined:
    Jul 30, 2012
    Posts:
    41
    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.
     
  4. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78
    Im searhing for this too , any update ?
     
  5. JacobK

    JacobK

    Joined:
    Jun 18, 2013
    Posts:
    20
    Any update on this? Is this possible yet, or is there an ETA for it?