Broken navmesh

I’ve been having this problem with my navmesh since forever and thought I should ask if anyone has good solution for it.

As you can see in the video below; the yellow spline represents a path that the agent will take to reach the goal. When it should clearly be a completely straight path, it instead zig-zags past, what appears to be, breaks or gaps in the nav mesh, caused by surrounding objects that affect it.

How can I improve my nav mesh to, at least, minimize these breaks?

Hello @ddibb1 ,
You could try disabling the Can Ever Affect Navigation option on the mesh that is generating this obstruction, as it may be causing unnecessary cuts in the NavMesh.

Another possible solution is to use the highest possible Cell Size and Cell Height values, as mentioned in the documentation, to reduce the NavMesh’s level of detail

I’m also sharing the Navigation documentation, which might be useful, as it presents other possible solutions to this type of navigation-related issue

Hope it helps!

Thanks for the reply! Disabling CanEverAffectNavigation might work for some smaller object, but as all characters, including the player’s characters in my game, are controlled by an AI controller and use the nav system to move around (think RTS controls), precision is very important. I think that kinda invalidates using very high Cell Size values as well.

Something is broken if that’s the path. The polygons don’t matter as long as they cover the area you want to travel. Is that the actual path the character takes? How are you generating the coordinates for the yellow line?

Yes, the character will take that path unless, of course, something changes in the path after the move has been executed.

The predicted path coordinates is mostly just from UNavigationSystemV1::FindPathToLocationSynchronously().

Very strange. FindPathToLocationSynchronously() ends up calling FindPathSync() which is what I’m using and I don’t get paths like that. They follow as straight a path as possible until they reach the edge of the navmesh.

What’s your cell size and tile size? Maybe post your generation settings in your navmesh.

How are you creating the holes or breaks in the navmesh? Are you using blocking volumes.

Note that you should turn off “Can Ever Affect Navigation” checkbox on everything that you can’t walk on. Affect Navigation means that it can be used to walk on. If it’s something that can BLOCK, then you need to use either a blocking volume or add a nav modifier component in that actor.

If it’s other actors that move around, those should not have affect navigation on. They should just have proper collision and they’ll go around each other just fine. You may need to set “Dynamic Obstacle” on their capsules.

I did not know that, I’ve been using it on all kinds of walls and stuff. For some objects I’m using nav modifiers.
For characters I’m only relying on the AI Detour Crowd avoidance system. No collision at all, and I don’t really have any other moving actors besides characters.

These are my current generation settings:

Also, not sure if it matters but I’m using a runtime dynamic generated nav mesh with invokers.

Decided to take a closer look at this in my own game. I have a tower defense game so pathfinding is very important (I use 3 nav meshes: ground, air and internal). I found one level with an open area and if there are obstacles forcing the enemies to go closer to the center of the area, it does exactly the same thing as in your video. For me, it’s such a short distance, I don’t really care. But it does look weird seeing enemies go to the center of an area and then suddenly turn for the only exit out of the area. In short, my earlier assertion that your pathfinding was broken was completely wrong.

I’ve been reading up a bit on navmesh and it seems they use something similar to A* that also uses an octree. The only smoothing it does is following along shared edges if the path gets shorter. But that’s it.

If you were to write your own smoothing function, there is a virtual method called OnPathUpdated() that you can use in your PathFollowingComponent. I use this to allow enemies to follow along side by side. So I nudge their paths to the left or right.

But if you have a smoothing function, you can apply it to your preview path and also call it inside OnPathUpdated().

Wish I had better news.

1 Like

Thanks a lot for looking into this, really appreciate it!

I’ll take a look at that path smoothing stuff but I’m kinda learning to code as I go, with no previous experience, so it might be above my skill level.

All of the above is good advice. The only other thing I’d recommend adding in is that remember that Unreal Engine’s nav mesh generation is not smooth over an infinitely pointed surface. It generates shapes and regions.

First thing I recommend is just turning on your P debug and just check that the area is all green and that there’s no height differentials or anything else that looks strange that could be affecting it.

The second thing I’d also recommend doing is you can increase the fidelity of the nav mesh itself by the settings that you’ve posted a bit earlier. You can decrease the size of each individual nav mesh area itself and therefore you will generate a much higher quality pathfinder.

If you’re generating your nav mesh statically and just allowing other actors and objects to affect it, then that should be okay. But performance can be a concern if your settings are asking for a very highly detailed nav mesh and you’re generating it dynamically and there are dynamic actors that are affecting the nav mesh.

Thanks everyone for your replies. In the end I managed to make the issue largely go away, in this instance, by simply tweaking the generation settings. It seemed that this specific part of my test level was reacting badly to certain Tile SIzes; any value between ~1500 - ~2000 caused the nav mesh, in this particular area, to turn really ugly.

A few example Tile Size UU values:

1024

1600

2048

1 Like