Problem with finding nearest "reacharble" node of target

Hi Aaron,

i am using your Pathfinding for my newest game, and i realy like your project - heve been using it for quite a time now in very different projects and was always very happy with it.

Now i am having some troubles in my current game and really don’t know how to fix this - perhaps you (or anybody els in this forum) has an idea how to do this.

First of all: a screenshot to illustrate my problem: the guy is an example start-position of a character (seeker start pos), the X is the desired “goal”, which is set to not walkable. I am using a grid graph, created at runtime and set the nodes to walkable/not walkable by myself. Generally this is working fine, but if i have some “unreachable” tiles/nodes like in the screenshot (Questionmark), the seeker always selects this unreachable tile and (of course) returns an error.

Is there any option i can enable, to calculate the path to not the nearest walkable, but the nearest “reachable” node? I think i could do this with multiGraph, but i do not own the professional version.

Thanks!

Hi

How are you setting the walkability manually?
If you are directly setting it on every node, make sure you call
AstarPath.active.FloodFill();
afterwards to recalculate some stuff so that the situation you describe should not happen.

Hi,

i am already doing this - i set node.Walkable to true or false o the specific node i want to change, and do a FloodFill() afterwards.

Ok… How are you requesting the paths? Using the Seeker’s StartPath code or something else?
What exactly is the error that the seeker gives back (the exact formulation can reveal what caused it).

I am requesting the path with standart seeker method:

seeker.StartPath(transform.position,goTo,PathComplete); Did already try to start it “manually”

`Pathfinding.ABPath p  = new Pathfinding.ABPath(transform.position,goTo,null);
		seeker.StartPath(p,PathComplete);`

same result. The exact error is: “No open points, whole area seached”. I already tried to debug the problem, and foud out that the “nearest node” is always the “bad” node ( the one which can’t be reached"):

NNInfo node = AstarPath.active.GetNearest(goTo, NNConstraint.Default );

When i run this directly before my path request, this always returns the node i marked with the questionmark in the screenshot.

No ideas how to fix this or maybe “workaround” somehow?

Hi

Hm…
Maybe it is because you are not doing the node updating when the pathfinding is paused.
Try instead
AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (delegate (bool force) { // update nodes AstarPath.instance.QueueWorkItemFloodFill(); return true; }

When ABPath searches for nodes it will first find the closest node to the start point, then it will find the closest point to the end node that is in the same connected component as the start node (the same connected component generally means that it is possible to reach the end from the start).

Also. When you are setting the walkability, are you recalculating its neighbours?
If not that could be the problem.

I recommend that you try to update the graph using the more high level graph updating API, see http://arongranberg.com/astar/docs/graph-updates.php

Thx Aron, i really did not think about using the high-level API you provide - used it, works like a charm.

I feel stupid now… :slight_smile: Thanks a lot!