Check if path has been created from pt A to B

I have a level in which I’m using a door. This door is tagged and the seeker is setting this door’s tag as not traversable. I have a waypoint on the opposite side of this door that I’d like my AI (using A* pathfinding) to traverse to this waypoint. Of course it cannot do this because of the door’s tag. Is there a way to check if this waypoint cannot be reached because of this tag?

Hi

You can check if two nodes can be reached using https://arongranberg.com/astar/docs/pathutilities.html#IsPathPossible3.

Thanks for your reply. I guess I don’t understand how to use this method properly. I’m not sure how I can convert my AI or target, into a node in order to check. Is that something I need to obtain before passing those arguments into this method?
Here is the code I’ve tried. However, if point2 is on the other side of a tag, it still thinks that there’s a path, even though there doesn’t appear to be.
GraphNode node1 = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
GraphNode node2 = AstarPath.active.GetNearest(aStar.transform.position, NNConstraint.Default).node;

    if (PathUtilities.IsPathPossible(node1, node2))
    {
        print("Yay, there is a path between those two nodes");
    }

Hi

You are not using the overload I linked to. Note that there is an overload of the IsPathPossible method that takes a tag mask (see my link above).

So it seems I am able to get the code part working:
GraphNode node1 = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
GraphNode node2 = AstarPath.active.GetNearest(moveTo.transform.position, NNConstraint.Default).node;
nodes.Add(node1);
nodes.Add(node2);

    if (!PathUtilities.IsPathPossible(nodes, 1))
    {
        print("I have no path");
    }

I have my door with a GraphUpdateScene component and a tag set to 1; I set the Seeker to have 1 not traversable. The issue I’m having now is, it chooses to create a partial path up to the door, even the full path can’t be created. I want this to check if a path can be made, if no, search for another path until you can find one.

Aren’t tags a flag like system. So wouldn’t it be
if (!PathUtilities.IsPathPossible(nodes, (1 << 1))...

1 Like