Error occur when I call FollowerEntity.GetRemainingPath()

I am implementing a combat system for a defense game. The logic is that when the AI detects an enemy, it sets ai.destination = target.position and approaches the enemy to attack.

However, when there is a barricade (OffMeshLink) blocking the path and an enemy is beyond the barricade, I set the barricade’s nodeLink2 start point as the destination. To do this, I use the following code:

var buffer = new List<Vector3>();
var parts = new List<PathPartWithLinkInfo>();
ai.GetRemainingPath(buffer, parts, out bool stale); 
foreach (var part in parts)
{
    if (part.type == Pathfinding.Funnel.PartType.OffMeshLink)
    {
        Debug.Log("There is OffMeshLink in the path");
        ai.destination = part.linkInfo.relativeStart;
        ai.SearchPath();
        return;
    }
}

This works fine when the barricade is not blocking the path, but when the barricade is blocking it, I encounter an error at ai.GetRemainingPath(buffer, parts, out bool stale);.

The error log is as follows:
InvalidOperationException: Operation is not valid due to the current state of the object. Pathfinding.Util.CircularBuffer1[T].PopStart () (at ./Packages/com.arongranberg.astar/Core/Collections/CircularBuffer.cs:93)Pathfinding.PathTracer.PopParts (System.Int32 count, Pathfinding.ITraversalProvider traversalProvider, Pathfinding.Path path) (at ./Packages/com.arongranberg.astar/Utilities/PathTracer.cs:1571) Pathfinding.FollowerEntity.GetRemainingPath (System.Collections.Generic.List1[T] buffer, System.Collections.Generic.List1[T] partsBuffer, System.Boolean& stale) (at ./Packages/com.arongranberg.astar/Core/AI/FollowerEntity.cs:1507)

Could this be a bug in the asset itself? Is there any possible solution?
(I’m using recast graph, offMeshLink(nodeLink2) and followerEntity)

Hi

When exactly do you run the code you posted?

The same error occurs when I query GetRemainingPath from a Monobehaviour. during the following callbacks (non-comprehensive list):

  • OnDrawGizmos()
  • Update()
  • LateUpdate()
  • FixedUpdate()

I don’t know when it is appropriate to call this function.

Hello are you updating the graph when the barricade is blocking it? Are you adding any extra functionality forcing the ai to keep searching for a path?

I realized that this error does not occur only in certain situations.
If you use GetRemainingPath while moving after setting the destination, an error occurs if there is an OffMeshLink, such as a barricade or ladder, on the path.

I discovered this while using it to display the route during movement. This is a duplicate question of the link below.

1 Like

Hi

Yes, this was indeed a bug. I have implemented a fix, and it will be included in the next update.

2 Likes