Exception: Some path is not cleaning up the flag1 field. This is a bug

Hi @aron_granberg , hope you’re well. I’m getting this exception a couple of seconds after enabling a GameObject that has a NavmeshCut component, which is in between 2 areas. It’s impossible to go from low ground to high ground with the missing piece, but it’s possible to go from high to low via a NodeLink2 (the white lines in the image)

// edit: using 4.2.18

So it seems to be happening when the target destination is set to the node on the left side, which is unreachable and the path fails. When the target becomes reachable and is set, then the exception is thrown. I could fix it by checking if the destination is reachable, but am not sure how to do that without performing pathfinding.

Here’s how I search for a new path:

var path = ABPath.Construct(PlayerActorPosition, destination);
path.nnConstraint = nnConstraint;
path.calculatePartial = allowPartial;
path.traversalProvider = traversal;
pathfindingSeeker.CancelCurrentPathRequest();
pathfindingSeeker.StartPath(path, callback, (int)CurrentNavmeshArea);

bump @aron_granberg , any fix in sight for this?

Hi

Hmm. Would it be possible for you to try this out with the beta version? I think it might be fixed in the beta already.

The beta requires 2022.2.10f1 or higher, but we’re using 2021.3 LTS. We can upgrade at this stage unfortunately

The way I’ve actually fixed the issue was to create a custom method that checks if the destination point is reachable

HashSet<GraphNode> processed = new(5000);
List<GraphNode> connections = new(10000);
public bool IsPointReachable(Vector3 point)
{
    if (!AstarPath.active)
        return false;

    connections.Clear();
    processed.Clear();
    var srcNode = AstarPath.active.GetNearest(PlayerActorPosition, nnConstraint).node;
    var dstNode = AstarPath.active.GetNearest(point, nnConstraint).node;
    return IsNodeReachable(srcNode);

    bool IsNodeReachable(GraphNode srcNode)
    {
        if (srcNode == null || dstNode == null || !srcNode.Walkable || !dstNode.Walkable)
            return false;

        if (srcNode == dstNode)
            return true;

        processed.Add(srcNode);
        int startIndex = connections.Count;
        int endIndex = startIndex;
        srcNode.GetConnections(node => {
            if (!processed.Contains(node) && node.Walkable)
            {
                connections.Add(node);
                endIndex++;
            }
        });
        for (int i = startIndex; i < endIndex; ++i)
            if (connections[i] == dstNode || IsNodeReachable(srcNode: connections[i]))
                return true;
        return false;
    }
}

Hi

Great that you managed to find a workaround.
I have not been able to replicate it in the latest beta.

I am experiencing the same issue after some debugging I found out that in ABPath class, there is a method called CompletedWith, and it is trying to cast node as GridNode, but my nodes were MeshNode so it caused the error.

Blockquote if (gridNode == null) {
throw new System.Exception(“Some path is not cleaning up the flag1 field. This is a bug.”);
}