Nav mesh shortest pathfinding error

Hi, I’ve been facing occasional errors when it comes to finding the shortest path along the navmesh. It doesn’t happen all the time, but I usually run into one of these errors when I try a dozen or two target locations for my pawn movement. I’ve attached a couple of images below to show the issue.

I’ve tried reducing the Tile Size, Cell Size and Agent Radius, as well as increasing the Heuristic scale past 1. However, I’m still not seeing much reduction in the occurrence of this issue, instead it just happens under different scenarios. Any other approaches that I could try to fix this up?

If you enabled drawing of navmesh polygons you’d see that these unexpected points on straight paths are caused by navmesh tile edges:

There are three things you could do about it:

  1. Leave the paths as they are since no will notice the path is off when AI is moving. If you need drawn paths to be “correct” you just need to implement your own path drawing that would make up for this imperfection.
  2. Post-process paths with raycasts on navmesh - these won’t get stuck on tile edges.
  3. Increase tile size as much as possible to reduce number of locations like that that would influence visible quality of your paths.

Solutions 1 and 2 are best and equally good so it depends on your preferences. 3 is just hiding the issue.

Hi, I might try path finding in the future, but for now I’d like to stick with the default navigation system. Unlike normal turn-based games, I’m not showing the navigable grid by default. Since the grid is being spawned only during click or touch events, it makes sense in my case to show the movement path. Also I’d like to add something similar to the reaction shots that were used in XCOM. In such situations, going around a different path might trigger unfair shots.

As for raycasts, even that requires implementing a new pathing algorithm right?

Increasing the tile size has taken care of the situation for now, but just out of curiosity, doesn’t that reduce the resolution of the nav mesh

It doesn’t reduce the resolution since voxel remains the same, it’s just more of them in one tile now. Mind that this will impact navmesh generation performance.

Regarding post-processing a path it would be enough to override UPathFollowingComponent::OnPathUpdated which gets called whenever AI gets a new path.