Tags don't affect path when agent is already moving

I’m trying to mimic the behaviour of a traffic intersection, my setup is roughly the same as in the Door1 example scene. I’m using a layered grid graph and currently an extension of the AIPath script.

My problem is that when the tag switches while the agents already have a path, they just walk right through the tagged area that they shouldn’t be able to walk on.

The behaviour is the same in the Door1 example scene so I figure my setup details shouldn’t be that relevant, and this might be more of a conceptual issue I’m running into. In that scene too, the DoorClosed tag only prevents the bot from walking if I try to set his destination while the door is still closed. If I toggle the door while he’s already on his way, he keeps on going and, if the door collider is turned off, walks straight through. That seems inconsistent to me, I was expecting him to stop in his tracks again whenever the door is toggled while he hasn’t cleared it yet.

I’ve just gotten started with the Pathfinding project, so I’m not sure to what degree that’s expected behavior and where I’d hook in to change it. Is there some place where I’d verify that the path is still walkable after changing the tags?

When looking at the path previews with the A* object selected, I also realized the path actually stops being visualized when it switches to ClosedDoor, so that made me think somewhere something about the validity of the path might be updating but the movement script isn’t reacting to it.

My second issue is that I’d ideally actually like agents to walk as close to the tagged area as they can, and continue on their way once it’s changed, instead of at first standing still wherever they spawn until the path is clear. Would be very grateful for pointers on how to approach either of those things.

Hi

Sorry for the very late answer.
Yeah I think this is due to how the AIPath script behaves when a path fails. Right now it will just continue with its current path if the path calculation fails. It is probably better, as you say, to just make it stop instead.

I have made changes in my dev version to clear the previous path if a path calculation fails and it will be included in the next version. You should be able to get the same behaviour if you change the AIPath.OnPathComplete method to also call SetPath(null) inside the if statement that checks for if p.error is true.

1 Like

Thanks for the answer! I’ve implemented the change in my override for now, and it’s helpful in my case

1 Like