A* Pathfinding Project  3.0.9
The A* Pathfinding Project for Unity
Path Class Reference

Basic path, finds the shortest path from A to B. More...

+ Inheritance diagram for Path:
+ Collaboration diagram for Path:

List of all members.

Public Member Functions

bool CanTraverse (Node node)  Returns if the node can be traversed.
bool IsDone ()  Returns if this path is done calculating.
void LogError (string msg)  Sets error to true and appends msg to errorLog and logs msg to the console.
 Path ()  Default constructor.
 Path (Vector3 start, Vector3 end, OnPathDelegate callbackDelegate)  Create a new path with a start and end point.
virtual void UpdateStartEnd (Vector3 start, Vector3 end)  Sets the start and end points.
virtual void Reset (Vector3 start, Vector3 end, OnPathDelegate callbackDelegate, bool reset=true)  
virtual void Prepare ()  Prepares the path.
virtual void Initialize ()  Initializes the path.
virtual float CalculateStep (float remainingFrameTime)  Calculates the path until completed or until the function duration has exceeded remainingFrameTime.
void ResetCosts (Path p)  Resets End Node Costs.
virtual void Trace (Node from)  Traces the calculated path from the end node to the start.
virtual string DebugString (PathLog logMode)  Returns a debug string for this path.
virtual void ReturnPath ()  Calls callback to return the calculated path.
Vector3 GetMovementVector (Vector3 point)  Returns in which direction to move from a point on the path.

Public Variables

OnPathDelegate callback  Callback to call when the path is complete.
bool recalcStartEndCosts = true  Defines if start and end nodes will have their connection costs recalculated for this path.
bool error = false  If the path failed, this is true.
string errorLog  Additional info on what went wrong.
bool foundEnd = false  Is the path completed?
Node[] path  Holds the path as a Node array.
Vector3[] vectorPath  Holds the (eventually smoothed) path as a Vector3 array.
Node startNode  Start node of the path.
Node endNode  End node of the path.
Node startHint  Hints can be set to enable faster Get Nearest Node queries.
Node endHint  Hints can be set to enable faster Get Nearest Node queries.
Vector3 originalStartPoint  
Vector3 originalEndPoint  
Vector3 startPoint  Exact start point of the path.
Vector3 endPoint  Exact end point of the path.
Int3 startIntPoint  Start point in integer coordinates.
Int3 hTarget  Target to use for H score calculations.
BinaryHeap open  Reference to the open list.
float duration  Number of ms of computation time for this path.
int searchIterations = 0  The number of frames/iterations this path has executed.
int searchedNodes  Number of nodes this path has searched.
System.DateTime callTime  When the call was made to start the pathfinding for this path.
bool processed = false  True if the path has been calculated (even if it had an error).
NNConstraint nnConstraint = PathNNConstraint.Default  Constraint for how to search for nodes.
Path next  The next path to be searched.
int radius  
int walkabilityMask = -1  A mask for defining what type of ground a unit can traverse, not used in any default standard graph.
int height  Height of the character.
int turnRadius  Turning radius of the character.
int speed  Speed of the character.
Heuristic heuristic  Determines which heuristic to use.
float heuristicScale = 1F  Scale of the heuristic values.
int pathID  ID of this path.
int enabledTags = -1  Which graph tags are traversable.

Static Public Variables

static System.Text.StringBuilder debugStringBuilder = new System.Text.StringBuilder ()  String builder used for all debug logging.

Protected Variables

float maxFrameTime  The max number of milliseconds per iteration (frame)
Node current  The node currently being processed.
bool hasEndPoint = true  Determines if a search for an end node should be done.
int[] endNodeCosts  Saved original costs for the end node.

Detailed Description

Basic path, finds the shortest path from A to B.

This is the most basic path object it will try to find the shortest path from A to B.
All other path types inherit from this type.

See also:
Seeker::StartPath

Constructor & Destructor Documentation

Path ( )

Default constructor.

Path ( Vector3  start,
Vector3  end,
OnPathDelegate  callbackDelegate 
)

Create a new path with a start and end point.

The delegate will be called when the path has been calculated. Do not confuse it with the Seeker callback as they are sent at different times. If you are using a Seeker to start the path you can set callbackDelegate to null


Member Function Documentation

virtual float CalculateStep ( float  remainingFrameTime) [virtual]

Calculates the path until completed or until the function duration has exceeded remainingFrameTime.

Usually a check is only done every 500 nodes if the time has exceeded remainingFrameTime.

Reimplemented in MultiTargetPath, RandomPath, ContourPath, ConstantPath, FloodPath, FloodPathTracer, CleanupPath65K, and XPath.

bool CanTraverse ( Node  node)

Returns if the node can be traversed.

This per default equals to if the node is walkable and if at least one of the node's tags match the enabledTags

virtual string DebugString ( PathLog  logMode) [virtual]

Returns a debug string for this path.

Warning:
This function should NOT be called simultaneously from multiple threads since that could mess up the static StringBuilder used

Reimplemented in MultiTargetPath.

Vector3 GetMovementVector ( Vector3  point)

Returns in which direction to move from a point on the path.

A simple and quite slow (well, compared to more optimized algorithms) algorithm first finds the closest path segment (from vectorPath) and then returns the direction to the next point from there. The direction is not normalized.

Returns:
Direction to move from a point, returns Vector3::zero if vectorPath is null or has a length of 0
virtual void Initialize ( ) [virtual]

Initializes the path.

Sets up the open list and adds the first node to it

Todo:
Might interfere with other paths since other paths might be calculated before callback is called

Reimplemented in MultiTargetPath, RandomPath, ContourPath, ConstantPath, FloodPathTracer, CleanupPath65K, and XPath.

bool IsDone ( )

Returns if this path is done calculating.

Returns:
If foundEnd or error is true.
Note:
The path might not have been returned yet.
Version:
Added in 3.0.8
See also:
Seeker::IsDone
void LogError ( string  msg)

Sets error to true and appends msg to errorLog and logs msg to the console.

Debug.Log call is only made if AstarPath::logPathResults is not equal to None and not equal to InGame

virtual void Prepare ( ) [virtual]

Prepares the path.

Searches for start and end nodes and does some simple checking if a path is at all possible

Reimplemented in MultiTargetPath, RandomPath, ContourPath, FloodPathTracer, FleePath, and CleanupPath65K.

void ResetCosts ( Path  p)

Resets End Node Costs.

Costs are updated on the end node at the start of the search to better reflect the end point passed to the path, the previous ones are saved in endNodeCosts and are reset in this function which is called after the path search is complete

virtual void ReturnPath ( ) [virtual]

Calls callback to return the calculated path.

See also:
callback

Reimplemented in RandomPath, and MultiTargetPath.

virtual void Trace ( Node  from) [virtual]

Traces the calculated path from the end node to the start.

This will build an array (path) of the nodes this path will pass through and also set the vectorPath array to the path arrays positions

Reimplemented in MultiTargetPath, RandomPath, and FloodPathTracer.

virtual void UpdateStartEnd ( Vector3  start,
Vector3  end 
) [virtual]

Sets the start and end points.

Sets #originalStartPoint, #originalEndPoint, startPoint, endPoint, startIntPoint and hTarget (to end )


Member Data Documentation

OnPathDelegate callback

Callback to call when the path is complete.

This is usually sent to the Seeker component which post processes the path and then calls a callback to the script which requested the path

System.DateTime callTime

When the call was made to start the pathfinding for this path.

Node current [protected]

The node currently being processed.

System.Text.StringBuilder debugStringBuilder = new System.Text.StringBuilder () [static]

String builder used for all debug logging.

float duration

Number of ms of computation time for this path.

The duration of this path in ms

int enabledTags = -1

Which graph tags are traversable.

This is a bitmask so -1 = all bits set = all tags traversable. For example, to set bit 5 to true, you would do

 myPath.enabledTags |= 1 << 5; 

To set it to false, you would do

 myPath.enabledTags &= ~(1 << 5); 
See also:
CanTraverse

Hints can be set to enable faster Get Nearest Node queries.

Only applies to some graph types

End node of the path.

int [] endNodeCosts [protected]

Saved original costs for the end node.

See also:
ResetCosts
Vector3 endPoint

Exact end point of the path.

bool error = false

If the path failed, this is true.

See also:
errorLog
string errorLog

Additional info on what went wrong.

See also:
error
bool foundEnd = false

Is the path completed?

bool hasEndPoint = true [protected]

Determines if a search for an end node should be done.

Set by different path types

Version:
Added in 3.0.8.3
int height

Height of the character.

Not used currently

Heuristic heuristic

Determines which heuristic to use.

float heuristicScale = 1F

Scale of the heuristic values.

Target to use for H score calculations.

See also:
Pathfinding::Node::h
float maxFrameTime [protected]

The max number of milliseconds per iteration (frame)

The next path to be searched.

Linked list implementation. You should never change this if you do not know what you are doing

Constraint for how to search for nodes.

Reference to the open list.

Shared between paths

Node [] path

Holds the path as a Node array.

All nodes the path traverses. This might not be the same as all nodes the smoothed path traverses.

int pathID

ID of this path.

Used to distinguish between different paths

bool processed = false

True if the path has been calculated (even if it had an error).

Used by the multithreaded pathfinder to signal that this path object is safe to return.

bool recalcStartEndCosts = true

Defines if start and end nodes will have their connection costs recalculated for this path.

These connection costs will be more accurate and based on the exact start point and target point, however it should not be used when connection costs are not the default ones (all build in graph generators currently generate default connection costs).

See also:
Int3.costMagnitude
Version:
Added in 3.0.8.3

Number of nodes this path has searched.

The number of frames/iterations this path has executed.

int speed

Speed of the character.

Not used currently

Hints can be set to enable faster Get Nearest Node queries.

Only applies to some graph types

Start point in integer coordinates.

Start node of the path.

Vector3 startPoint

Exact start point of the path.

Turning radius of the character.

Not used currently

Vector3 [] vectorPath

Holds the (eventually smoothed) path as a Vector3 array.

int walkabilityMask = -1

A mask for defining what type of ground a unit can traverse, not used in any default standard graph.

See also:
enabledTags

The documentation for this class was generated from the following file:
 All Classes Functions Variables Enumerations Properties