If cannot reach target?

I’m not sure if this has been answered, but what can I do in C# if there is no possible way to get to the target (player)? I’m using the GraphUpdate component to let the user place barricades, and I want to have the barrier turn red or be destroyed if the zombies can’t reach him (because he’s blocking them from him). Thanks!


For exactly that reason, there is the UpdateGraphsNoBlock method. It takes two (or more) nodes and tries to update the graphs with a specific GraphUpdateObject, then it checks if those two nodes can still have valid paths between them, if not, it will revert the graph update and return false (in which case you can make the barrier turn red or something).

See http://arongranberg.com/astar/docs/class_pathfinding_1_1_graph_update_utilities.php#af1d9912f395e3a1b5ef4f21d1f19da74

In the current version there is however a bug (some old development code I forgot to remove) which makes it impossible to use this code without getting exceptions. So you need to open up the file name “astarclasses.cs” and find the method named “RevertFromBackup” (around line 493). Replace the contents of that method with:

`/** Reverts penalties and flags (which includes walkability) on every node which was updated using this GUO.

  • Data for reversion is only saved if #trackChangedNodes is true */
    public virtual void RevertFromBackup () {
    if (trackChangedNodes) {
    if (changedNodes == null) return;

     for (int i=0;i<changedNodes.Count;i++) {
     	changedNodes[i].Penalty = (uint)(backupData[i]>>32);
     	changedNodes[i].Flags = (uint)(backupData[i] & 0xFFFFFFFF);
     	changedNodes[i].position = backupPositionData[i];
     ListPool<GraphNode>.Release (changedNodes);

    } else {
    throw new System.InvalidOperationException (“Changed nodes have not been tracked, cannot revert from backup”);

and then it will work correctly.