A* Pathfinding Project  4.1.7
The A* Pathfinding Project for Unity 3D
GraphUpdateUtilities Class Reference

Contains useful functions for updating graphs. More...

Detailed Description

Contains useful functions for updating graphs.

This class works a lot with the GraphNode class, a useful function to get nodes is AstarPath.GetNearest.

See also
AstarPath.GetNearest
Pathfinding.PathUtilities
Since
Added in 3.1

Static Public Member Functions

static bool UpdateGraphsNoBlock (GraphUpdateObject guo, GraphNode node1, GraphNode node2, bool alwaysRevert=false)
 Updates graphs and checks if all nodes are still reachable from each other. More...
 
static bool UpdateGraphsNoBlock (GraphUpdateObject guo, List< GraphNode > nodes, bool alwaysRevert=false)
 Updates graphs and checks if all nodes are still reachable from each other. More...
 

Member Function Documentation

◆ UpdateGraphsNoBlock() [1/2]

static bool UpdateGraphsNoBlock ( GraphUpdateObject  guo,
GraphNode  node1,
GraphNode  node2,
bool  alwaysRevert = false 
)
static

Updates graphs and checks if all nodes are still reachable from each other.

Graphs are updated, then a check is made to see if the nodes are still reachable from each other. If they are not, the graphs are reverted to before the update and false is returned.
This is slower than a normal graph update. All queued graph updates and thread safe callbacks will be flushed during this function.

Note
This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0). So when using this, it is recommended to set AstarPath.minAreaSize to 0 (A* Inspector -> Settings -> Pathfinding)
Parameters
guoThe GraphUpdateObject to update the graphs with
node1Node which should have a valid path to node2. All nodes should be walkable or false will be returned.
node2Node which should have a valid path to node1. All nodes should be walkable or false will be returned.
alwaysRevertIf true, reverts the graphs to the old state even if no blocking occurred
Returns
True if the given nodes are still reachable from each other after the guo has been applied. False otherwise.
var guo = new GraphUpdateObject(tower.GetComponent<Collider>().bounds);
var spawnPointNode = AstarPath.active.GetNearest(spawnPoint.position).node;
var goalNode = AstarPath.active.GetNearest(goalPoint.position).node;
if (GraphUpdateUtilities.UpdateGraphsNoBlock(guo, spawnPointNode, goalNode, false)) {
// Valid tower position
// Since the last parameter (which is called "alwaysRevert") in the method call was false
// The graph is now updated and the game can just continue
} else {
// Invalid tower position. It blocks the path between the spawn point and the goal
// The effect on the graph has been reverted
Destroy(tower);
}

◆ UpdateGraphsNoBlock() [2/2]

static bool UpdateGraphsNoBlock ( GraphUpdateObject  guo,
List< GraphNode nodes,
bool  alwaysRevert = false 
)
static

Updates graphs and checks if all nodes are still reachable from each other.

Graphs are updated, then a check is made to see if the nodes are still reachable from each other. If they are not, the graphs are reverted to before the update and false is returned. This is slower than a normal graph update. All queued graph updates will be flushed during this function.

Note
This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0). So when using this, it is recommended to set AstarPath.minAreaSize to 0. (A* Inspector -> Settings -> Pathfinding)
Parameters
guoThe GraphUpdateObject to update the graphs with
nodesNodes which should have valid paths between them. All nodes should be walkable or false will be returned.
alwaysRevertIf true, reverts the graphs to the old state even if no blocking occurred
Returns
True if the given nodes are still reachable from each other after the guo has been applied. False otherwise.

The documentation for this class was generated from the following file: