Unit cannot find a path to a reachable destination


I have a grid graph that units seem to have very odd behaviour on. I can clearly see that the grid has generated walkable tiles, yet depending on where my unit and target is, sometimes it will complain there is no way to reach the destination.

Here is a picture showing the situation:

The unit is trying to reach the location of the gizmo, the error i get in the console is:
Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Couldn’t find a node close to the end point
Path Number 2 (unique id)
UnityEngine.Debug:LogWarning (object)
AstarPath:LogPathResults (Pathfinding.Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:814)
AstarPath:b__122_1 (Pathfinding.Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1288)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler) (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:379)
Pathfinding.PathProcessor/<>c__DisplayClass24_0:<.ctor>b__0 () (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:108)
System.Threading.ThreadHelper:ThreadStart ()

the code im using to figure out which resource is closest is:

        foreach (var target in targets)
            GameObject workingPointTarget = target.GetComponent<MapResource>().CheckAnyWorkingPoint();

            if (workingPointTarget != null && IsPathReachable(workingPointTarget))
                var path = ABPath.Construct(transform.position, workingPointTarget.transform.position);

                yield return path.WaitForPath();

                if (!path.error)
                    int pathLength = path.vectorPath.Count;  // Gets the number of tiles

                    if (pathLength < shortestPathLength)
                        shortestPathLength = pathLength;
                        closestGameObject = target;

but path.error is ALWAYS true, i just don’t see how it can be, the colliders on the unit and the destination don’t overlap ?

any ideas on this one?

EDIT; I should also mention, i have two seperate grid graphs in this situation, one for the enemy units on the main path, and the units can traverse the second grid graph which contains everything else. The Viewer for the enemy grid graph is turned off in the picture so you can see what the unit graph picture looks like.


Since you have two graphs, I must note that your pathfinding request does not specify which of the graphs to use. You might want to specify this using

path.nnConstraint.graphMask = 1 << graphIndex;

or if you are using the beta version, you could do something like:

path.nnConstraint.graphMask = GraphMask.FromGraphName("My Graph");

as otherwise it will just pick the closest graph to the start point (which may not be the one you want).

Thank you, that fixed all the issues I had :slight_smile: