PointOnNavmesh returns null when exactly on an edge in Recast graph

This seems like a bug, but perhaps it’s by design and I’m misunderstanding what the function is doing.

I’m using a Recast graph for my layout, and I have various “interaction nodes” placed around the world as potential destinations for my ai agents. When selecting an interaction node, I use PointOnNavmesh to determine if that node is within the navmesh (since it’s possible that a navmesh cut might have cut it out), and this was working perfectly fine.

I messed with the recast graph properties a bit, namely the tiling, and suddenly all of my agents no longer saw the interaction nodes as available; the PointOnNavmesh function was returning null for all of them. After scratching my head for hours, I tried moving them around a little bit, and all of a sudden they started working again. Looking at it closer, it seems like at the tile size I selected, it just so happened that all of them landed exactly on the edge between two tris in the navmesh.

Is this intended behaviour? Are edges between tris in the navmesh not considered to be “on the navmesh”?

For what its worth, there is no issue with finding paths to the point, it’s just the PointOnNavmesh call that fails.

I’m using version 4.3.75, in Unity 2023.1.0b12

It looks like the issue comes from PointOnNavmesh calling GetNearest with a maxDistanceSqr of 0. I’m guessing the distance to the node on either side of the edge is slightly more than 0, so no node ends up getting returned.

I was able to fix the issue by calling GetNearest with a maxDistanceSqr of 0.1f instead of using PointOnNavmesh.