Search Unity

Inefficient Mesh Memory Allocation

Discussion in 'Editor & General Support' started by joshuacwilde, Nov 19, 2018.

  1. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    As I have done some research and profiling, I realized that Unity is allocating a lot of memory for meshes. It seems to allocate up to 4x what I would expect. Meshes should just contain the vertex, color, and uv data, if I understand correctly, so I'm not sure why Unity allocates a lot more than what is required for that.

    I'm currently being forced to write my game in Unity, but then write the procedural generation and even mesh rendering in native code as part of a plugin (using Metal and OpenGL). This is a really cumbersome process, and it is because Unity uses an inefficient amount of memory for meshes.

    Is there someone from the dev team that would be able to break this down for me? Specifically what goes into the memory allocations for meshes?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
  3. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    Thanks. They are created procedurally and marked not readable, and that helps a little bit.

    I would just like to see a breakdown of where the memory goes. Meshes shouldn't be using that much memory. It just doesn't make sense.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
  5. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    Thanks. I have already done a lot of profiling. I created a blank scene with only procedurally created meshes. The meshes are definitely the problem.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    So what does the profiler say? I much memory does a single mesh use?

    What index format are you using? https://docs.unity3d.com/ScriptReference/Mesh-indexFormat.html

    Does the mesh have normals and tangents? How many uv sets do you have, are you sure it only has 1?
    Can you inspect the mesh in the inspector? It should tell you all the channels that are used in the preview.