Get the Nearest Walkable node

Hi, I’m trying to get the nearest walkable node, however it keeps returning null, because the nearest node to the position is not walkable.

I am currently doing the following:

`
NNConstraint nodeConstraint = new NNConstraint();
nodeConstraint.constrainWalkability = true;
nodeConstraint.walkable = true;

NNInfo nodeInfo = AstarPath.active.GetNearest(_transform.position, nodeConstraint);
`

But the nodeInfo.node and nodeInfo.constrainedNode is always null, even though I know there is a walkable node nearby.

Is it not possible to get the nearest walkable node using the above approach?

Hi

Yes, that should be the right way to do it.
Actually you don’t even have to assign constrainWalkability or walkable, they are set to those values by default.

Try setting A* Inspector -> Settings -> Max Nearest Node Distance to something higher.
Alternatively set nodeConstraint.constrainDistance = false.

Constraining the distance did the trick. I had tried increasing the max nearest node distance but that had other unwanted side-effects to the gameplay.

Thanks for the help!