ConstantPath not working

So, I’ve been trying to implement a random Wander behaviour in my NPCs and after some thought I decided to use the ConstantPath, but the problem is, it only ever returns 1 node.

Graph type: Recast
A* version: 4.2.15
Unity version: 2019.4.8f1 LTS

This is my code:

currently: maxDistance is equal to 5, casted as int because it is a float
so, multiplied by 1000 it should return all nodes within 5 walkable meters from my current node, as far as I understood the usage of ConstantPath

However, upon receiving the callback, I get this:
constantPath.allNodes.Count == 1

When there are clearly nodes within 5 meters from my character:

(Red circle is the character, white dots are random points on constantPath.allNodes, white square is the selected random node it is wandering towards.)

The path is ignoring all other nodes, unless the distance is set to a higher number (10 meters for example, and even so, it only selects at most 2 nodes, disregarding closer nodes).


The ConstantPath searches the graph based on the distances between node centers. In this case, the “path” to the node to the right of the agent will first have to go to the center of the node it is currently in, and then to the other node. A distance which is probably larger than 5 meters.

What I’d recommend for your use case is to start a constant path with a search range that includes a margin. And then when you generate random points, discard any points further away than your desired maximum distance.