Check if Graph contains point

i need to check if a specific point is reachable, but need the condition for it to fail to be whether the point simply lies on the graph. I’m using a navmesh graph. I tried using isPathPossible, but GetNearest() doesn’t seem suitable as it returns a valid ‘nearest’ point on the graph, lowering the distance in the main settings is not an option as the characters center is a certain height above the ground. I saw the, but i definitely plan on having more than one graph of the same type (especially navmesh ones). So i guess the only way is to loop through and cast every graph to RecastGraph and if not null use the PointOnNavmesh, or is there an easier way?

Edit: i think it’s something like this what i need: Is there a GetNearest() that returns null if the point is not on a grid?

Edit2: i just realized that Navmeshgraph and recastgraph are different types, so what can i do to achieve what i want?

Edit3: I can’t see a way to find a path between two nodes, only between positions, but that could help as i could try distance-checking the nodes i get from Getnearest.

The core of my problem is that i have npcs that should not go to a target if it is outside the navmesh

1 Like


Usually it is good to leave a small margin so that if the target is just outside the navmesh, it will still find it.

The easiest possible solution is

var nnConstraint = NNConstraint.Default;
var nearestPoint =;
nearestPoint.y = somePosition.y;
if ((nearestPoint - somePosition).sqrMagnitude > 0.5*0.5) { // Or some other very small constant
     // Inside!

The only potential problem is if the nearest node is on a slope, then the nearest point will not be the point which is directly below it in XZ space, but it should be fine as long as your valid target points are not too far above the navmesh.

For a recast graph the best solution would be to loop through the graphs and test for PointOnNavmesh.

1 Like

Thx, so i can be sure that the position i get from GetNearest(positionEnd) is the same that seeker.StartPath(positionStart, positionEnd) finds with positionEnd ?

Yes. The code uses that method internally.
There is one case where it will be different. The closest point might not be reachable from the start point, so it will try to find the closest node to the end point which can be reached from the start point.

Okay, i guess IsPathPossible can be used for that, so thank you, i will do it this way.