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.List
1[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)