Calculated path is complete even though it shouldn't be

Hey, so I’m using a coroutine to check if a unit has a valid path during runtime. However, it appears to be incorrectly thinking that a valid path exists when one does not.

while(true) {
        if (pathToCheck == null || pathToCheck.IsDone()) {
          pathToCheck = ABPath.Construct(transform.position, attackTarget.transform.position, (Path p) => {
            Debug.Log("Check path while attack callback");
            Debug.Log(p.CompleteState);
            if (p.error && !staticLookObject.IsObserved) {
              Debug.Log("Can't reach target");
              _cantReachTimer.Start();
            } else {
               Debug.Log("Can reach target");
              _cantReachTimer.StopAndReset();
            }
          });
          AstarPath.StartPath(pathToCheck);
        }        
        yield return Timing.WaitForSeconds(0.5f);
      }

Here you can see it in action - the AI On the right is trying to path to the player on the left through a closed door, the door was previously open but then closed and updated the grid around it

Even though the unit won’t go through the door, the AstarPath.StartPath() returns a CompleteState of Complete. Any idea what’s going on?

Thanks

Hi

By default the system will try to find a path to a point as close as possible to the target point. It will find a path if it could reach a point within A* Inspector -> Settings -> Max Nearest Node Distance world units.
It’s a bit confusing with the ‘Partial’ enum that exists, that was added for a potential future, but which isn’t much used nowadays.

If you want to check if a point is reachable in a much faster and easier way you could use the PathUtilities.IsPathPossible method.

Good call, I have switched to using that instead on all of my AI - thanks for the clarification!

1 Like