How do I set MaxNearestNodeDistance on a per search basis?

I have many agents using all kinds of searches continuously, in several threads, so I’m thinking that I cannot simply change this parameter at the beginning of each search since it could screw up any of the other queued or currently processing searches.

Hi

Unfortunately at the moment you can only enable or disable MaxNearestNodeDistance to be taken into account, but you cannot set the value exactly per path. http://arongranberg.com/astar/docs/class_pathfinding_1_1_n_n_constraint.php#aea0c9d05190ca41a290ff4ef197c7d84

However if you need to change this, I do not think it would be that hard to change the AstarPath.GetNearest function to use a new field in the NNConstraint as the distance limit.

Thanks Aaron, I’ll check it out.

Hi again,

I’ve been looking into this. After reading the docs and going through your code the first step is to create a path where I can specify the NNConstraint. So I attempted (guided by your docs http://www.arongranberg.com/astar/docs/calling-pathfinding.php) to replace this:

seeker.StartPath(transform.position, TargetPosition, OnPathComplete);

with this:

ABPath path = ABPath.Construct(transform.position, TargetPosition, null);

seeker.StartPath(path, OnPathComplete);

This fails with the error:

Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Couldn’t find a close node to the end point

(there are nodes at both positions and this works fine with the first code snippet)

Hi

That’s odd because the call above should do exactly the same thing.
The seeker.StartPath(a, b, callback) method does this

return StartPath(GetNewPath(start, end), callback);

And the GetNewPath method does

return ABPath.Construct(start, end, null);

Are you sure there is not something else that is different?

Argh! Stupid mistake. Confusing TargetPosition with targetPosition. Sorry for troubling you.