Search Unity

How to manually modify the navigation mesh. I need to remove individual triangles.

Discussion in 'Navigation' started by ZoopTEK, Mar 4, 2021.

  1. ZoopTEK

    ZoopTEK

    Joined:
    Feb 14, 2012
    Posts:
    22
    I have identified bad triangles in the navigation mesh. They're inside solid objects. I just need to delete them, but cannot see a way to assign the navigation mesh triangles.

    Please God, tell me how...?

    From what I can tell, it all gets hidden in the NavMeshData class, with no ability to access triangles. You have to use a vague "give me triangulation," which seems to give you all the triangles from all nav mesh surfaces. Although not great, good enough for what I need to do for now

    ---Rambling Angry Rant Ahead---

    I have been fighting this for three days. I am NOT a happy camper.

    All of this stems from the fact that Unity will create navigation mesh triangles inside solid objects, including colliders. Yes, before you ask, yes I have it seek colliders.
    • I have tried NavMeshObstacles. They consistently work, but they're rectangular, not triangles. And slapping potentially thousands of NavMeshObstacles for every triangle, or slapping NavMeshObstacles on every single potentially offending piece of a prefab, in a random map generator, is absolutely BONKERS. I would have to hire an army!
    • NavMeshModifierVolumes seem like the same thing as NavMeshObstacles, in that they're rectangular, but potentially not detected when baking.
    • NavMeshModifiers: I bloody hate these things with a passion. They seem like the solution. I have even generated a custom mesh, with mesh collider, that covers the offending nav mesh triangles, but it only works SOMETIMES. It is absolutely inconsistent. They will work in a brand new scene, but not a scene from the game, despite using the same steps, same game objects, etc. Other users on the forum have gone as far as logging out that the baker is aware of the modifiers, but it's still ignoring them... sometimes. You can't fathom the frustration of having the tool right there in front of you, but it only works... sometimes.
    • LocalNavMeshBuilder and NavMeshSourceTag only seem to extend navmeshes, not modify existing.
    I am getting to the point where I am going to start buying other pathfinding solutions off the asset store, and redo the whole frick'n pathfinding in the game, when I should have released an update DAYS ago. You know how amazingly dangerous that is? Can you imagine the pressure of having to rip out a core system when you're already days behind schedule!?

    ---Rambling Angry Rant Over---

    Sorry for that, but I just needed to let someone know how much pressure I'm under.

    Please, someone out there, please bless me with your navigation guidance, because I am at my wit's end!
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    I can feel your pain. I have had similar problems and it is frustrating to run into those brick walls.
    Could you provide a small sample project? I might be able to help.
     
  3. ZoopTEK

    ZoopTEK

    Joined:
    Feb 14, 2012
    Posts:
    22
    Since we can't consistently fix the navigation mesh triangles, I ended up having to do a "live" version of the detection.

    I wrote a wrapper for the NavMesh.SamplePosition method, which will run my logic for determining if a point is unnavigable upon the result of NavMesh.SamplePosition. If its unnavigable, it will do a few retries to nearby positions.

    It's not nearly as efficient as baking the navmesh correctly, but, the best I can do right now. I put in a ton of caching and it seems to be fast enough, and I don't see anything snapping inside solid obstacles... so far.

    I hope someone will see this, like Unity themselves, and see we need a way to manipulate the triangles, or at least fix the bloody NavMeshModifier to consistently work.
     
  4. ZoopTEK

    ZoopTEK

    Joined:
    Feb 14, 2012
    Posts:
    22
    Bump.

    I would love an official response from Unity regarding editing triangles of a nav mesh.

    I just got my first report that my jank solution, is indeed, jank. Surprise surprise. I need a real solution.
     
    Tymianek likes this.
  5. Jimbo_93

    Jimbo_93

    Joined:
    Mar 2, 2021
    Posts:
    7
    Being able to edit the mesh manually would be nice, but the bigger problem seems like the fact that it's generating the mesh inside of objects in the first place. I haven't run into this issue yet, but now I'm worried...

    Any rhyme or reason to it? Does changing the voxel size help?
     
    Tymianek likes this.
  6. cpuRunningHot

    cpuRunningHot

    Joined:
    May 5, 2018
    Posts:
    94
    Any new insights on this issue? Encountering it at the moment. It *appears* like the NavMesh generation is only considering the distance to the surface with no consideration for inside/outside.

    Are there any standard techniques for dealing with this? If the ground is perfectly flat, then one can simply be careful to not overlap the thing ( wall, etc ) with the ground. But with uneven terrain, etc. it would be extremely problematic to have to manually ensure that objects don't poke through the ground.

    Or do we simply have to deal with the fact that there will be inaccessible patches of navmesh inside objects here and there?

    p.s. For me, decreasing the voxel size did not help. Took longer, but still get a patch of navmesh inside the overlapped area.

    Are the voxels rendered on the surface of the mesh or filling the volume? Suspecting surface only based on observed behavior.
     
    Last edited: Jun 7, 2022
    Tymianek likes this.