A* Pathfinding Project  4.1.9
The A* Pathfinding Project for Unity 3D
GridNodeBase Class Referenceabstract

Base class for GridNode and LevelGridNode. More...

Detailed Description

Base class for GridNode and LevelGridNode.

Public Member Functions

override void AddConnection (GraphNode node, uint cost)
 Add a connection from this node to the specified node. More...
 
override void ClearConnections (bool alsoReverse)
 Remove all connections from this node. More...
 
void ClearCustomConnections (bool alsoReverse)
 Same as ClearConnections, but does not clear grid connections, only custom ones (e.g added by AddConnection or a NodeLink component) More...
 
override bool ContainsConnection (GraphNode node)
 Checks if this node has a connection to the specified node. More...
 
override void DeserializeReferences (GraphSerializationContext ctx)
 Used to deserialize references to other nodes e.g connections. More...
 
override void FloodFill (System.Collections.Generic.Stack< GraphNode > stack, uint region)
 
override void GetConnections (System.Action< GraphNode > action)
 Calls the delegate with all connections from this node. More...
 
override void GetConnections (System.Action< Connection > action)
 Calls the delegate with all connections and respective costs from this node. More...
 
override int GetGizmoHashCode ()
 Hash code used for checking if the gizmos need to be updated. More...
 
abstract GridNodeBase GetNeighbourAlongDirection (int direction)
 Adjacent grid node in the specified direction. More...
 
override void Open (Path path, PathNode pathNode, PathHandler handler)
 Open the node. More...
 
override Vector3 RandomPointOnSurface ()
 A random point on the surface of the node. More...
 
override void RemoveConnection (GraphNode node)
 Removes any connection from this node to the specified node. More...
 
override void SerializeReferences (GraphSerializationContext ctx)
 Used to serialize references to other nodes e.g connections. More...
 
override float SurfaceArea ()
 The surface area of the node in square world units. More...
 
override void UpdateRecursiveG (Path path, PathNode pathNode, PathHandler handler)
 Internal method to update the G score. More...
 
- Public Member Functions inherited from GraphNode
virtual void DeserializeNode (GraphSerializationContext ctx)
 Deserializes node data (for example when loading graphs from file). More...
 
virtual void FloodFill (Stack< GraphNode > stack, uint region)
 Internal method to run a flood fill in order to recalculate the Area property. More...
 
virtual bool GetPortal (GraphNode other, List< Vector3 > left, List< Vector3 > right, bool backwards)
 Add a portal from this node to the specified node. More...
 
virtual void OpenCooperative (CooperativeABPath path, PathNodeCooperative pathNode, CooperativePathHandler handler)
 Open the node cooperatively. More...
 
virtual void RecalculateConnectionCosts ()
 Recalculates all connection costs from this node. More...
 
virtual void SerializeNode (GraphSerializationContext ctx)
 Serializes node data (for example when saving graphs to file). More...
 

Public Attributes

Connection [] connections
 
- Public Attributes inherited from GraphNode
const uint MaxAreaIndex = FlagsAreaMask >> FlagsAreaOffset
 
const uint MaxGraphIndex = FlagsGraphMask >> FlagsGraphOffset
 Max number of graphs-1. More...
 
Int3 position
 Position of the node in world space. More...
 

Protected Member Functions

 GridNodeBase (AstarPath astar)
 
- Protected Member Functions inherited from GraphNode
 GraphNode (AstarPath astar)
 Constructor for a graph node. More...
 

Protected Attributes

ushort gridFlags
 
int nodeInGridIndex
 Bitfield containing the x and z coordinates of the node as well as the layer (for layered grid graphs). More...
 
const int NodeInGridIndexLayerOffset = 24
 
const int NodeInGridIndexMask = 0xFFFFFF
 
- Protected Attributes inherited from GraphNode
uint flags
 Bitpacked field holding several pieces of data. More...
 

Properties

abstract bool HasConnectionsToAllEightNeighbours [get]
 True if the node has grid connections to all its 8 neighbours. More...
 
int NodeInGridIndex [get, set]
 The index of the node in the grid. More...
 
bool TmpWalkable [get, set]
 Temporary variable used internally when updating the graph. More...
 
bool WalkableErosion [get, set]
 Stores walkability before erosion is applied. More...
 
int XCoordinateInGrid [get]
 X coordinate of the node in the grid. More...
 
int ZCoordinateInGrid [get]
 Z coordinate of the node in the grid. More...
 
- Properties inherited from GraphNode
uint Area [get, set]
 Connected component that contains the node. More...
 
bool Destroyed [get]
 
uint Flags [get, set]
 Holds various bitpacked variables. More...
 
NavGraph Graph [get]
 Graph which this node belongs to. More...
 
uint GraphIndex [get, set]
 Graph which contains this node. More...
 
int NodeIndex [get, private set]
 Internal unique index. More...
 
uint Penalty [get, set]
 Penalty cost for walking on this node. More...
 
uint Tag [get, set]
 Node tag. More...
 
bool TemporaryFlag1 [get, set]
 Temporary flag for internal purposes. More...
 
bool TemporaryFlag2 [get, set]
 Temporary flag for internal purposes. More...
 
bool Walkable [get, set]
 True if the node can be traversed. More...
 

Private Attributes

const int GridFlagsWalkableErosionMask = 1 << GridFlagsWalkableErosionOffset
 
const int GridFlagsWalkableErosionOffset = 8
 
const int GridFlagsWalkableTmpMask = 1 << GridFlagsWalkableTmpOffset
 
const int GridFlagsWalkableTmpOffset = 9
 

Additional Inherited Members

- Package Functions inherited from GraphNode
void Destroy ()
 Destroys the node. More...
 

Constructor & Destructor Documentation

◆ GridNodeBase()

GridNodeBase ( AstarPath  astar)
protected

Member Function Documentation

◆ AddConnection()

override void AddConnection ( GraphNode  node,
uint  cost 
)
virtual

Add a connection from this node to the specified node.

If the connection already exists, the cost will simply be updated and no extra connection added.

Note
Only adds a one-way connection. Consider calling the same function on the other node to get a two-way connection.

Implements GraphNode.

◆ ClearConnections()

override void ClearConnections ( bool  alsoReverse)
virtual

Remove all connections from this node.

Parameters
alsoReverseif true, neighbours will be requested to remove connections to this node.

Implements GraphNode.

◆ ClearCustomConnections()

void ClearCustomConnections ( bool  alsoReverse)

Same as ClearConnections, but does not clear grid connections, only custom ones (e.g added by AddConnection or a NodeLink component)

◆ ContainsConnection()

override bool ContainsConnection ( GraphNode  node)
virtual

Checks if this node has a connection to the specified node.

Reimplemented from GraphNode.

◆ DeserializeReferences()

override void DeserializeReferences ( GraphSerializationContext  ctx)
virtual

Used to deserialize references to other nodes e.g connections.

Use the GraphSerializationContext.GetNodeIdentifier and GraphSerializationContext.GetNodeFromIdentifier methods for serialization and deserialization respectively.

Nodes must override this method and serialize their connections. Graph generators do not need to call this method, it will be called automatically on all nodes at the correct time by the serializer.

Reimplemented from GraphNode.

◆ FloodFill()

override void FloodFill ( System.Collections.Generic.Stack< GraphNode stack,
uint  region 
)

◆ GetConnections() [1/2]

override void GetConnections ( System.Action< GraphNode action)
virtual

Calls the delegate with all connections from this node.

node.GetConnections(connectedTo => {
Debug.DrawLine((Vector3)node.position, (Vector3)connectedTo.position, Color.red);
});

You can add all connected nodes to a list like this

var connections = new List<GraphNode>();
node.GetConnections(connections.Add);

Implements GraphNode.

◆ GetConnections() [2/2]

override void GetConnections ( System.Action< Connection action)
virtual

Calls the delegate with all connections and respective costs from this node.

Implements GraphNode.

◆ GetGizmoHashCode()

override int GetGizmoHashCode ( )
virtual

Hash code used for checking if the gizmos need to be updated.

Will change when the gizmos for the node might change.

Reimplemented from GraphNode.

◆ GetNeighbourAlongDirection()

abstract GridNodeBase GetNeighbourAlongDirection ( int  direction)
pure virtual

Adjacent grid node in the specified direction.

This will return null if the node does not have a connection to a node in that direction.

The dir parameter corresponds to directions in the grid as:

Z
|
|
6 2 5
\ | /
-- 3 - X - 1 ----- X
/ | \
7 0 4
|
|
See also
GetConnections

Implemented in LevelGridNode, and GridNode.

◆ Open()

override void Open ( Path  path,
PathNode  pathNode,
PathHandler  handler 
)
virtual

Open the node.

Adds all neighbours of this node to the open list.

See also
https://en.wikipedia.org/wiki/A*_search_algorithm

Implements GraphNode.

◆ RandomPointOnSurface()

override Vector3 RandomPointOnSurface ( )
virtual

A random point on the surface of the node.

For point nodes and other nodes which do not have a surface, this will always return the position of the node.

Reimplemented from GraphNode.

◆ RemoveConnection()

override void RemoveConnection ( GraphNode  node)
virtual

Removes any connection from this node to the specified node.

If no such connection exists, nothing will be done.

Note
This only removes the connection from this node to the other node. You may want to call the same function on the other node to remove its eventual connection to this node.

Implements GraphNode.

◆ SerializeReferences()

override void SerializeReferences ( GraphSerializationContext  ctx)
virtual

Used to serialize references to other nodes e.g connections.

Use the GraphSerializationContext.GetNodeIdentifier and GraphSerializationContext.GetNodeFromIdentifier methods for serialization and deserialization respectively.

Nodes must override this method and serialize their connections. Graph generators do not need to call this method, it will be called automatically on all nodes at the correct time by the serializer.

Reimplemented from GraphNode.

◆ SurfaceArea()

override float SurfaceArea ( )
virtual

The surface area of the node in square world units.

Reimplemented from GraphNode.

◆ UpdateRecursiveG()

override void UpdateRecursiveG ( Path  path,
PathNode  pathNode,
PathHandler  handler 
)
virtual

Internal method to update the G score.

Internal method to update the G score for this node and all children of it in the search graph

Reimplemented from GraphNode.

Member Data Documentation

◆ connections

Connection [] connections

◆ gridFlags

ushort gridFlags
protected

◆ GridFlagsWalkableErosionMask

const int GridFlagsWalkableErosionMask = 1 << GridFlagsWalkableErosionOffset
private

◆ GridFlagsWalkableErosionOffset

const int GridFlagsWalkableErosionOffset = 8
private

◆ GridFlagsWalkableTmpMask

const int GridFlagsWalkableTmpMask = 1 << GridFlagsWalkableTmpOffset
private

◆ GridFlagsWalkableTmpOffset

const int GridFlagsWalkableTmpOffset = 9
private

◆ nodeInGridIndex

int nodeInGridIndex
protected

Bitfield containing the x and z coordinates of the node as well as the layer (for layered grid graphs).

See also
NodeInGridIndex

◆ NodeInGridIndexLayerOffset

const int NodeInGridIndexLayerOffset = 24
protected

◆ NodeInGridIndexMask

const int NodeInGridIndexMask = 0xFFFFFF
protected

Property Documentation

◆ HasConnectionsToAllEightNeighbours

abstract bool HasConnectionsToAllEightNeighbours
get

True if the node has grid connections to all its 8 neighbours.

Note
This will always return false if GridGraph.neighbours is set to anything other than Eight.
See also
GetNeighbourAlongDirection

◆ NodeInGridIndex

int NodeInGridIndex
getset

The index of the node in the grid.

This is x + z*graph.width So you can get the X and Z indices using

int index = node.NodeInGridIndex;
int x = index % graph.width;
int z = index / graph.width;
// where graph is GridNode.GetGridGraph (node.graphIndex), i.e the graph the nodes are contained in.

◆ TmpWalkable

bool TmpWalkable
getset

Temporary variable used internally when updating the graph.

◆ WalkableErosion

bool WalkableErosion
getset

Stores walkability before erosion is applied.

Used internally when updating the graph.

◆ XCoordinateInGrid

int XCoordinateInGrid
get

X coordinate of the node in the grid.

The node in the bottom left corner has (x,z) = (0,0) and the one in the opposite corner has (x,z) = (width-1, depth-1)

See also
ZCoordInGrid
NodeInGridIndex

◆ ZCoordinateInGrid

int ZCoordinateInGrid
get

Z coordinate of the node in the grid.

The node in the bottom left corner has (x,z) = (0,0) and the one in the opposite corner has (x,z) = (width-1, depth-1)

See also
XCoordInGrid
NodeInGridIndex

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