Closest Path (partial path)?

Hi. I’m developing a game (similar to Baldur’s Gate) and I need the party to go where the player has clicked. But the issue is that even if the player click inside a wall the pathfinder must get the nearest walkable area. Is there a way for the seeker to return the closest path?

(In the image the yellow cross represents the clicked position and the green cross represents the nearest (desired) position)

As you can see, the does not work (the way I tested it at least) since the clicked area is “walkable”.


Why is the clicked area walkable?? is really your best option~

If you could further explain how you tested it, and why it did not work hopefully I can write up some working code :slight_smile:

The clicked (pink-ish) area should not be walkable, but there are nodes on the pink area. The doesn’t know that those nodes(pink graph) shouldn’t be reachable, because it doesn’t know that I only want to search on the blue graph. If I use on the yellow cross position it will return the nearest node on the pink graph/area instead of a node on the blue graph.


This is the default behavior for paths.
Make sure you set seeker->StartEndModifier->EndPoint to ClosestOnNode and it should work well. If you get path failed messages you might need to increase A* Inspector -> Settings -> Max Nearest Node Distance.

Internally this is handled by a GetNearest call with a special NNConstraint.

Node a =;

//Make sure the second node is in the same area as the first node
NNConstraint c = NNConstraint.Default;
c.constrainArea = true;
c.area = a.area;

Node b = (target.position, c);

Setting the “A* Inspector -> Settings -> Max Nearest Node Distance” to a higher value did solve the problem (no other changes required). Thanks.