AStarSeeker PostProcess Behavior - Bug?

I am using ABPath.Construct() to constract a path and it works very well.

Once ABPath.CompleteState is PathCompleteState.Complete, I call AStarSeeker.PostProcess(Path).

I’m experiencing an issue where, sporadically, PostProcess() fails to populate ABPath.vectorPath. The generated path is an empty list.

When this behavior manifests, 1) I can confirm the path is complete, 2) it is not partial, 3) it has start and end nodes, and 4) it has a populated list of triangle meshes in its path. It appears that PostProcess is blocking, but I also confirm isDone is true before checking the state of vectorPath.

The console log shows the path was completed and there are no errors logged:
“Path Completed : Computation Time 0.50 ms Searched Nodes 34 Path Length 9 Path Cost: 28947”

Is this a bug? What things should I be looking at when PostProcess fails to generate a list?

Thanks,
Shaun

ABPath.vectorPath is empty before PostProcess. ABPath’s Completed state lead me to believe that pathing was successful. I’m retrying with

PathUtilities.IsPathPossible(p.path).

If this is only happening intermittently it definitely sounds like a bug. Can you post maybe the list of coordinates for paths that do properly post process (for reference sake) and also the relevant parts of the code? Gonna tag @aron_granberg on this one for review.

1 Like

Hi

Check

path.IsDone() instead.

CompleteState=Complete is set before some cleanup code has run, so just checking that would be liable to race conditions.

However, in most cases I would recommend either using the callbacks, or using path.WaitForPath.

See Searching for paths - A* Pathfinding Project

2 Likes

@tealtxgr OK – I will provide additional telemetry.

Understood. I will check for path.isDone() in my script’s update loop. If this fails, I will try a callback.

if (_AIPath.CompleteState == PathCompleteState.Complete && _AIPath.IsDone())
{
   GameState.Instance.AstarSeeker.PostProcess(_AIPath);
   _Waypoints = _AIPath.vectorPath;
}
else if (_AIPath.CompleteState == PathCompleteState.Error)
{
#if (UNITY_EDITOR)
   if (_LogPathfindingErrors)
      Debug.LogError($"Error calculating path for AI player {aiPlayer.Name}, Source={_AIPath.startPoint}, Destination={_AIPath.endPoint}, {_AIPath.errorLog}", this);
#endif
}

OK –

More testing is necessary, but it does appear to be a race condition. I switched to the above code and still encountered empty paths. After switching to callbacks the path is consistently populated.

My next step is to try on more geographically complex maps with larger numbers of agents. Thank you for the helpful feedback and support.

That’s very strange. Do you think you could post your complete code?

Here is the first version of the code. The issue is that Completed would be true, and vectorPath was randomly empty after successful path creation. I added _AIPath.isDone() to my condition logic and I believe I saw the error again – but perhaps I was mistaken.

private void Update()
{
   float distance = Vector3.Distance(sourcePlayerPosition, targetPlayerPosition);
   if (_AIPath == null && distance > minimumPathCalculationDistance)
   {
       NavGraph navGraph = GameState.Instance.AstarPath.graphs[0];
      _AIPath = ABPath.Construct(sourcePlayerPosition, targetPlayerPosition);
      AstarPath.StartPath(_AIPath);
   }

   if (_AIPath != null)
   {
       if (_AIPath.CompleteState == PathCompleteState.Complete)
       {
           GameState.Instance.AstarSeeker.PostProcess(_AIPath);
           _Waypoints = _AIPath.vectorPath;
           _IsPathfindingError = false;
       }
       else if (_AIPath.CompleteState == PathCompleteState.Error)
       {
Debug.LogError($"Error calculating path for AI player {aiPlayer.Name}, Source=   {_AIPath.startPoint}, Destination={_AIPath.endPoint}, 
           _IsPathfindingError = true;
       }
   }
}

Since switching to callbacks and the logic shown in the documentation you shared, I have not seen the behavior manifest.