How to deal with old paths being used by agents and updated GridGraphs?

Since the GridGraph can be updated after a path has being calculated my idea is to always check walkability before moving into a node, like this:

if (path.path[currentWayPoint].walkable)
//move using path.vectorPath[currentWayPoint]
else
//calculate a new path

So my question is: is path.path.Count always equals to path.vectorPath.Count? Or is there any other way to deal with this problem?

Another question: My game is really simple so my idea is to disable Collision testing on the GridGraph and just use tags on the Seeker to handle walkable and not walkable nodes, is this a possible approach?

Thanks so much! I’m so excited I found this Pathfinding library.

I think I need to clarify the problem. Lets say an agent got a path and is moving towards its target position and I put a building in the middle of its path (updating GridPath accordingly), how do I deal with this? If the agent keep moving through the old path it will go through the building (not desirable behavior).

In the scenes examples, the agents solve this problem by recomputing their path frequently, it’s every 500ms if I remember well (repathRate variable of AIPath class).

I often just add a Delegate called “UpdatePaths” then subscribe what paths need updating ~ Just add an Event call to the GraphUpdateScene calling method~

Or you can use Unit’s (Broadcast message) if your not that up on Delegate’s and Event’s.

This way you only call UpdatePaths when its needed.

1 Like

Extending Burdock’s answer. There is a global delegate which you might be interested in.

http://arongranberg.com/astar/docs_FeatureFreeze/class_astar_path.php#a8c6d31ec81922e83c11aaf8a96f33cb2
`
AstarPath.OnGraphsUpdated += RecalculatePaths;

public void RecalculatePaths (AstarPath script) {
…
}`