Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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:
    40
    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:
    152
    It's on our roadmap but not available now, sorry!
     
  3. daterre

    daterre

    Joined:
    Jul 30, 2012
    Posts:
    40
    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:
    66
    Im searhing for this too , any update ?
     
  5. JacobK

    JacobK

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