A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
Node Class Reference

Holds one node in a navgraph. More...

+ Inheritance diagram for Node:
+ Collaboration diagram for Node:

Public Member Functions

void AddConnection (Node node, int cost)
 Add a connection to the node with the specified cost.
 
void BaseFloodFill (Stack< Node > stack, int area)
 Adds all connecting nodes to the stack and sets the area variable to area.
 
int[] BaseInitialOpen (BinaryHeapM open, Int3 targetPosition, Int3 position, Path path, bool doOpen)
 
void BaseOpen (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path)
 Opens the nodes connected to this node.
 
void BaseResetCosts (int[] costs)
 Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).
 
virtual bool ContainsConnection (Node node)
 Returns true if this node has a connection to the node.
 
virtual void FloodFill (Stack< Node > stack, int area)
 Adds all connecting nodes to the stack and sets the area variable to area.
 
virtual void GetConnections (NodeDelegate callback)
 Get all connections for a node.
 
void GetConnectionsBase (NodeDelegate callback)
 Get all connections for a node.
 
int GetNodeIndex ()
 Returns the global node index.
 
virtual int[] InitialOpen (BinaryHeapM open, Int3 targetPosition, Int3 position, Path path, bool doOpen)
 
virtual void Open (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path)
 
void RecalculateConnectionCosts (bool neighbours)
 Recalculate costs for each connection.
 
virtual bool RemoveConnection (Node node)
 Removes the connection to the node if it exists.
 
virtual void ResetCosts (int[] costs)
 Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).
 
void SetNodeIndex (int index)
 
virtual void UpdateAllG (NodeRun nodeR, NodeRunData nodeRunData)
 
virtual void UpdateConnections ()
 Remove connections to unwalkable nodes.
 
void UpdateG (NodeRun nodeR, NodeRunData nodeRunData)
 
void UpdateH (Int3 targetPosition, Heuristic heuristic, float scale, NodeRun nodeR)
 Calculates and updates the H score.
 
virtual void UpdateNeighbourConnections ()
 Calls UpdateConnections on all neighbours.
 

Static Public Member Functions

static int Abs (int x)
 Implementation of the Absolute function.
 

Public Attributes

int[] connectionCosts
 Cost for the connections to other nodes.
 
Node[] connections
 List of all connections from this node.
 
int flags
 Bit packed values for different fields.
 
Int3 position
 Position in world space of the node.
 

Protected Member Functions

void BaseUpdateAllG (NodeRun nodeR, NodeRunData nodeRunData)
 

Properties

int area [get, set]
 Area ID of the node.
 
bool Bit15 [get, set]
 Returns bit 15 from flags.
 
bool Bit16 [get, set]
 Returns bit 16 from flags.
 
bool Bit8 [get, set]
 Returns bit 8 from flags.
 
int graphIndex [get, set]
 The index of the graph this node is in.
 
uint penalty [get, set]
 
int tags [get, set]
 Tags for walkability.
 
bool walkable [get, set]
 Is the node walkable.
 

Private Attributes

uint _penalty
 Penlty cost for walking on this node.
 
const int AreaBitNumber = 24
 1 << WalkableBitNumber
 
const int AreaBitsSize = 0xFF
 Size of the area bits.
 
const int GraphIndexBitNumber = 18
 
const int GraphIndexBitsSize = 0x1F
 
int nodeIndex
 Global node index.
 
const int NotAreaBits = ~(AreaBitsSize << AreaBitNumber)
 The bits in flags which are NOT area bits.
 
const int NotGraphIndexBits = ~(GraphIndexBitsSize << GraphIndexBitNumber)
 Bits which are NOT graphIndex bits.
 
const int WalkableBit = 1 << WalkableBitNumber
 
const int WalkableBitNumber = 23
 Bit number for the walkable bool.
 

Detailed Description

Holds one node in a navgraph.

A node is a simple object in the shape of a square (GridNode), triangle (NavMeshNode), or point (the rest).
A node has a position and a list of neighbour nodes which are the nodes this node can form a straight path to
Size: (4*3)+4+4+4+4+4+4+8+8*n = 44+8*n bytes where n is the number of connections (estimate)

Member Function Documentation

void AddConnection ( Node  node,
int  cost 
)

Add a connection to the node with the specified cost.

If a connection to the node already exists, this function will only change the cost of it.

Note
This will create a one-way connection, consider calling the same function on the other node too.
GridGraphs use custom connections and has a fixed cost for connections to neighbour nodes. So you will not be able to modify costs to neighbour nodes on grid graphs with this function.
See Also
RemoveConnection
Pathfinding::Int3::costMagnitude

+ Here is the caller graph for this function:

void BaseFloodFill ( Stack< Node stack,
int  area 
)

Adds all connecting nodes to the stack and sets the area variable to area.

This is a base function and can be called by node classes overriding the FloodFill function to add the connections in the connections array

+ Here is the caller graph for this function:

void BaseOpen ( NodeRunData  nodeRunData,
NodeRun  nodeR,
Int3  targetPosition,
Path  path 
)

Opens the nodes connected to this node.

This is a base call and can be called by node classes overriding the Open function to open all connections in the connections array.

See Also
connections
Open

+ Here is the call graph for this function:

void BaseResetCosts ( int[]  costs)

Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).

This is called at the end of a pathfinding search

+ Here is the caller graph for this function:

virtual bool ContainsConnection ( Node  node)
virtual

Returns true if this node has a connection to the node.

Note
this might not return true for node classes using their own connection system (like GridNode)

+ Here is the caller graph for this function:

virtual void GetConnections ( NodeDelegate  callback)
virtual

Get all connections for a node.

This function will call the callback with every node this node is connected to. In contrast to the connections array this function also includes custom connections which for example grid graphs use.

Since
Added in version 3.2

Reimplemented in GridNode.

+ Here is the call graph for this function:

void GetConnectionsBase ( NodeDelegate  callback)

Get all connections for a node.

This function will call the callback with every node this node is connected to. This is a base function and will simply loop through the connections array.

See Also
GetConnections

+ Here is the caller graph for this function:

int GetNodeIndex ( )

Returns the global node index.

Used for internal pathfinding purposes

+ Here is the caller graph for this function:

void RecalculateConnectionCosts ( bool  neighbours)

Recalculate costs for each connection.

All standard connections, which means those stored in the connections array will have their costs recalculated. Non-standard connections such as most grid graph connections will not be recalculated (mostly because they are constant and cannot be recalculated).

Parameters
neighboursIf true, recalculates connection costs on this node's neighbours as well. This makes sure costs are calculated correctly (the same) in both directions.
Note
Assumes the correct cost is simply the distance between the nodes (in Int3 space). This is what the built-in graphs (e.g Point Graph) use, so it should be fine.
virtual bool RemoveConnection ( Node  node)
virtual

Removes the connection to the node if it exists.

Returns true if a connection was removed, returns false if no connection to the node was found

Note
This will only remove the connection from this node to node, but it will still exist in the other direction consider calling the same function on the other node too
See Also
AddConnection

Reimplemented in GridNode.

+ Here is the caller graph for this function:

virtual void ResetCosts ( int[]  costs)
virtual

Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).

This is called at the end of a pathfinding search

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void UpdateConnections ( )
virtual

Remove connections to unwalkable nodes.

This function loops through all connections and removes the ones which lead to unwalkable nodes.
This can speed up performance if a lot of nodes have connections to unwalkable nodes, they usually don't though

Note
This function does not add connections which might have been removed previously

Reimplemented in GridNode.

+ Here is the caller graph for this function:

void UpdateH ( Int3  targetPosition,
Heuristic  heuristic,
float  scale,
NodeRun  nodeR 
)

Calculates and updates the H score.

Calculates the H score with respect to the target position and chosen heuristic.

Parameters
targetPositionThe position to calculate the distance to.
heuristicHeuristic to use. The heuristic can also be hard coded using pre processor directives (check sourcecode)
scaleScale of the heuristic
nodeRNodeRun object associated with this node.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void UpdateNeighbourConnections ( )
virtual

Calls UpdateConnections on all neighbours.

Neighbours are all nodes in the connections array. Good to use if the node has been set to unwalkable-

See Also
UpdateConnections

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

uint _penalty
private

Penlty cost for walking on this node.

This can be used to make it harder/slower to walk over certain areas.

const int AreaBitNumber = 24
private

1 << WalkableBitNumber

Bit number at which area starts

int [] connectionCosts

Cost for the connections to other nodes.

The cost of moving from this node to connections[x] is stored in connectionCosts[x].

See Also
connections
Node [] connections

List of all connections from this node.

This node's neighbour nodes are stored in this array.

Note
Not all connections are stored in this array, some node types (such as Pathfinding::GridNode) use custom connection systems which they store somewhere else.
See Also
connectionCosts
int flags

Bit packed values for different fields.

It's amazing how much information you can store in an integer! Below you can see a table showing how the different bits are used:

Area Walkability Graph Index Graph Specific Values Tags (tag) Bit 8 - Path specific value Graph specific values
Walkable before erosion (Grid Graph and derived only) Used as a tag by some path types (GridGraph only) Connections
Bit 313029282726252423222120191817 1615141312111098765432 10
Do not get or set this variable directly, instead, get or set the appropriate properties.

See Also
walkable
area
graphIndex
Bit8
tags
Int3 position

Position in world space of the node.

The position is stored as integer coordinates to avoid precision loss when the node is far away from the world origin. The default precision is 0.001 (one millimeter).

See Also
Pathfinding.Int3

Property Documentation

int area
getset

Area ID of the node.

Nodes which there are no valid path between have different area values.

Note
Small areas can have have the same area ID since only 256 ID values are available
See Also
AstarPath::minAreaSize
bool Bit15
getset

Returns bit 15 from flags.

In the GridGraph (and derived) it is used to store if walkable before erosion.

See Also
GridNode::WalkableErosion
bool Bit16
getset

Returns bit 16 from flags.

Graphs can use this value for any kind of data storage. Grid Graphs use it as a temporary variable when updating graphs using erosion.

See Also
GridNode::WalkableErosion
bool Bit8
getset

Returns bit 8 from flags.

Used to flag special nodes with special pathfinders

int graphIndex
getset

The index of the graph this node is in.

See Also
AstarData.graphs
int tags
getset

Tags for walkability.

Determines which tag is set for this node. 0...31.

Warning
Do NOT pass a value larger than 31 to this variable, that could affect other parameters since it's bit-packed.

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