Search Unity

Mesh Collider Partially Working on Large Terrain Mesh

Discussion in 'Editor & General Support' started by ede0m, Jan 20, 2021.

  1. ede0m

    ede0m

    Joined:
    Dec 12, 2020
    Posts:
    7
    Hello!

    I have made a high vert "dense" mesh in blender that I use as terrain in my unity project. I have successfully used a mesh of about 1 million by simply checking "generate mesh collider" on the model in the editor and applying this setting.

    However, when I make the mesh more dense and increase the number of vertices to 4 million, then follow the same import process, only part of the generated mesh collider seems to be working. That is, my character can stand on this terrain in certain spots, but as it moves, it will suddenly fall through the mesh as if the mesh collider is missing huge sections of the mesh. I have triple checked that the mesh collider is using the same mesh that is rendered.

    Intuitively, it seems like the mesh collider is not lined up with the mesh. Is there a way I can verify this? I have looked around on he documentation, but haven't noticed any threshold for number of vertices with non-convex mesh colliders.

    Another thing worth noting is that when importing the mesh from blender to Unity, the scale is set to 100 for some reason. This scaling did not seem to cause problems with the "smaller" 1m vert mesh.

    Any insight is much appreciated!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    Is your MeshCollider marked as Convex?
     
  3. ede0m

    ede0m

    Joined:
    Dec 12, 2020
    Posts:
    7
    Thanks for the thought. It is not marked as convex. I believe there is a 256 triangle limit on convex mesh colliders.
     
  4. ede0m

    ede0m

    Joined:
    Dec 12, 2020
    Posts:
    7
    To add some more information.. I noticed that collision is only being applied in the positive quadrant of the XZ plane. That is, as soon as the character moves into -x, or -z position quad, it will begin to fall. I don't have much of an inclination as to why this is happening. It just seems that the parts of the mesh in those quadrants are not being used by collision system. Sliding the whole terrain into the positive quadrant seems to crash Unity.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    Yeah my thought was perhaps you had it set to convex and were running into the triangle limit.

    Woah that's wild!

    It's possible you've run into a bug or at least an undocumented or poorly-documented limitation of Unity. Might be worth preparing a bug report for it... At the very least you might get confirmation that what you're doing isn't really feasible or supported by Unity.

    In the meantime... Do you really need that much detail on one mesh? Can the mesh be split up into smaller pieces?
     
  6. ede0m

    ede0m

    Joined:
    Dec 12, 2020
    Posts:
    7
    Haha most likely not. I think I do need a highly dense mesh on my terrain for a vertex displacement shader I have (since tessellation is not yet supported in URP shadergraph), but it can certainly be reduced while persisting this effect.

    I am likely going to go the route of splitting the terrain mesh up into pieces as you have mentioned. I haven't looked too much into how Unity handles this yet, but do you know if there is a way to make Unity's collision system only check collisions for terrain pieces that are "near"? Perhaps it does this under the hood already.