A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
Path Class Referenceabstract
+ Inheritance diagram for Path:
+ Collaboration diagram for Path:

Public Member Functions

void AdvanceState (PathState s)
 Threadsafe increment of the state.
 
abstract void CalculateStep (long targetTick)
 
bool CanTraverse (Node node)
 Returns if the node can be traversed.
 
void Claim (System.Object o)
 Claim this path.
 
virtual string DebugString (PathLog logMode)
 Returns a debug string for this path.
 
void Error ()
 Aborts the path because of an error.
 
void ForceLogError (string msg)
 Logs an error and calls Error() to true.
 
PathState GetState ()
 Returns the state of the path in the pathfinding pipeline.
 
uint GetTagPenalty (int tag)
 Returns penalty for the given tag.
 
float GetTotalLength ()
 Total Length of the path.
 
abstract void Initialize ()
 Initializes the path.
 
bool IsDone ()
 Returns if this path is done calculating.
 
void Log (string msg)
 Appends a message to the errorLog.
 
void LogError (string msg)
 Appends msg to errorLog and logs msg to the console.
 
virtual void OnEnterPool ()
 Called when the path enters the pool.
 
abstract void Prepare ()
 
void PrepareBase (NodeRunData runData)
 Prepares low level path variables for calculation.
 
void Release (System.Object o)
 Releases a path claim.
 
void ReleaseSilent (System.Object o)
 Releases the path silently.
 
virtual void Reset ()
 Reset all values to their default values.
 
virtual void ReturnPath ()
 Calls callback to return the calculated path.
 
virtual void Trace (NodeRun from)
 Traces the calculated path from the end node to the start.
 

Public Attributes

OnPathDelegate callback
 Callback to call when the path is complete.
 
System.DateTime callTime
 When the call was made to start the pathfinding for this path.
 
float duration
 The duration of this path in ms.
 
int enabledTags = -1
 Which graph tags are traversable.
 
int height
 Height of the character.
 
Heuristic heuristic
 Determines which heuristic to use.
 
float heuristicScale = 1F
 Scale of the heuristic values.
 
Path next
 The next path to be searched.
 
NNConstraint nnConstraint = PathNNConstraint.Default
 Constraint for how to search for nodes.
 
List< Nodepath
 Holds the path as a Node array.
 
ushort pathID
 ID of this path.
 
int radius
 Radius for the unit searching for the path.
 
bool recycled = false
 True if the path is currently recycled (i.e in the path pool).
 
NodeRunData runData
 
int searchedNodes
 Number of nodes this path has searched.
 
int searchIterations = 0
 
int speed
 Speed of the character.
 
int turnRadius
 Turning radius of the character.
 
List< Vector3 > vectorPath
 Holds the (perhaps post processed) 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.
 

Protected Member Functions

bool HasExceededTime (int searchedNodes, long targetTime)
 
abstract void Recycle ()
 Recycle the path.
 

Protected Attributes

int[] _tagPenalties = new int[0]
 Penalties for each tag.
 
NodeRun currentR
 The node currently being processed.
 
bool hasBeenReset = false
 True if the Reset function has been called.
 
float maxFrameTime
 The max number of milliseconds per iteration (frame, in case of non-multithreading)
 

Properties

PathCompleteState CompleteState [get, set]
 
bool error [get]
 If the path failed, this is true.
 
string errorLog [get]
 Log messages with info about eventual errors.
 
int[] tagPenalties [get, set]
 Penalties for each tag.
 

Private Member Functions

void ErrorCheck ()
 Does some error checking.
 

Private Attributes

string _errorLog = ""
 Additional info on what went wrong.
 
Node[] _path
 
Vector3[] _vectorPath
 
List< System.Object > claimed = new List<object>()
 
PathCompleteState pathCompleteState
 
bool releasedNotSilent = false
 
PathState state
 
System.Object stateLock = new object()
 

Member Function Documentation

bool CanTraverse ( Node  node)

Returns if the node can be traversed.

This per default equals to if the node is walkable and if the node's tag is included in enabledTags

+ Here is the caller graph for this function:

void Claim ( System.Object  o)

Claim this path.

A claim on a path will ensure that it is not recycled. If you are using a path, you will want to claim it when you first get it and then release it when you will not use it anymore. When there are no claims on the path, it will be recycled and put in a pool.

See Also
Release
Recycle

+ Here is the caller graph for this function:

void Error ( )

Aborts the path because of an error.

Sets error to true. This function is called when an error has ocurred (e.g a valid path could not be found).

See Also
LogError

+ Here is the caller graph for this function:

void ErrorCheck ( )
private

Does some error checking.

This is called before from BasePrepare. Makes sure the user isn't using old code paths and that no major errors have been done.

Exceptions
Anexception if any errors are found

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ForceLogError ( string  msg)

Logs an error and calls Error() to true.

This is called only if something is very wrong or the user is doing something he/she really should not be doing.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint GetTagPenalty ( int  tag)

Returns penalty for the given tag.

Parameters
tagA value between 0 (inclusive) and 31 (inclusive).

+ Here is the caller graph for this function:

float GetTotalLength ( )

Total Length of the path.

Calculates the total length of the vectorPath. Cache this rather than call this function every time since it will calculate the length every time, not just return a cached value.

Returns
Total length of vectorPath, if vectorPath is null positive infinity is returned.
abstract void Initialize ( )
pure virtual

Initializes the path.

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

Implemented in MultiTargetPath, ABPath, RandomPath, FloodPath, ConstantPath, FloodPathTracer, and XPath.

+ Here is the caller graph for this function:

bool IsDone ( )

Returns if this path is done calculating.

Returns
If CompleteState is not PathCompleteState.NotCalculated.
Note
The path might not have been returned yet.
Since
Added in 3.0.8
See Also
Seeker::IsDone

+ Here is the caller graph for this function:

void Log ( string  msg)

Appends a message to the errorLog.

Nothing is logged to the console.

void LogError ( string  msg)

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. Consider calling Error() along with this call.

+ Here is the caller graph for this function:

virtual void OnEnterPool ( )
virtual

Called when the path enters the pool.

This method should release e.g pooled lists and other pooled resources The base version of this method releases vectorPath and path lists. Reset() will be called after this function, not before.

Warning
Do not call this function manually.

Reimplemented in MultiTargetPath, and ConstantPath.

void PrepareBase ( NodeRunData  runData)

Prepares low level path variables for calculation.

Called before a path search will take place. Always called before the Prepare, Initialize and CalculateStep functions

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

abstract void Recycle ( )
protectedpure virtual

Recycle the path.

Calling this means that the path and any variables on it are not needed anymore and the path can be pooled. All path data will be reset. Implement this in inheriting path types to support recycling of paths.

public override void Recycle () {
//Recycle the Path (<Path> should be replaced by the path type it is implemented in)
PathPool<Path>.Recycle (this);
}
Note
Do not call this function directly, instead use the Claim and Release functions.
See Also
Pathfinding.PathPool
Reset
Claim
Release

Implemented in ABPath, FloodPath, MultiTargetPath, ConstantPath, RandomPath, and XPath.

+ Here is the caller graph for this function:

void Release ( System.Object  o)

Releases a path claim.

Removes the claim of the path by the specified object. When the claim count reaches zero, the path will be recycled, all variables will be cleared and the path will be put in a pool to be used again. This is great for memory since less allocations are made.

See Also
Claim

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ReleaseSilent ( System.Object  o)

Releases the path silently.

This will remove the claim by the specified object, but the path will not be recycled if the claim count reches zero unless a Release call (not silent) has been made earlier. This is used by the internal pathfinding components such as Seeker and AstarPath so that they will not recycle paths. This enables users to skip the claim/release calls if they want without the path being recycled by the Seeker or AstarPath.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void Reset ( )
virtual

Reset all values to their default values.

All inheriting path types must implement this function, resetting ALL their variables to enable recycling of paths. Call this base function in inheriting types with base.Reset ();

Reimplemented in ABPath, ConstantPath, FloodPath, FloodPathTracer, RandomPath, and XPath.

+ Here is the call graph for this function:

virtual void ReturnPath ( )
virtual

Calls callback to return the calculated path.

See Also
callback

Reimplemented in MultiTargetPath, and RandomPath.

+ Here is the caller graph for this function:

virtual void Trace ( NodeRun  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. Assumes the vectorPath and path are empty and not null (which will be the case for a correctly initialized path).

Reimplemented in MultiTargetPath.

+ Here is the caller graph for this function:

Member Data Documentation

string _errorLog = ""
private

Additional info on what went wrong.

See Also
error
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

float duration

The duration of this path in ms.

How long it took to calculate the path The number of frames/iterations this path has executed. This is the number of frames when not using multithreading. When using multithreading, this value is quite irrelevant

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);

The Seeker has a popup field where you can set which tags to use.

Note
If you are using a Seeker. The Seeker will set this value to what is set in the inspector field on StartPath. So you need to change the Seeker value via script, not set this value if you want to change it via script.
See Also
CanTraverse
bool hasBeenReset = false
protected

True if the Reset function has been called.

Used to allert users when they are doing it wrong.

int height

Height of the character.

Not used currently

Path next

The next path to be searched.

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

List<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.

ushort pathID

ID of this path.

Used to distinguish between different paths

int radius

Radius for the unit searching for the path.

Note
Not used by any built-in pathfinders. These common name variables are put here because it is a lot faster to access fields than, for example make use of a lookup table (e.g dictionary). Or having to cast to another path type for acess.
bool recycled = false

True if the path is currently recycled (i.e in the path pool).

Do not set this value. Only read. It is used internally.

int speed

Speed of the character.

Not used currently

int turnRadius

Turning radius of the character.

Not used currently

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
Note
Not used by any built-in pathfinders. These variables are put here because it is a lot faster to access fields than, for example make use of a lookup table (e.g dictionary)

Property Documentation

bool error
get

If the path failed, this is true.

See Also
errorLog
string errorLog
get

Log messages with info about eventual errors.

int [] tagPenalties
getset

Penalties for each tag.

Tag 0 which is the default tag, will have added a penalty of tagPenalties[0]. These should only be positive values since the A* algorithm cannot handle negative penalties.

Note
This array will never be null. If you try to set it to null or with a lenght which is not 32. It will be set to "new int[0]".
If you are using a Seeker. The Seeker will set this value to what is set in the inspector field on StartPath. So you need to change the Seeker value via script, not set this value if you want to change it via script.
See Also
Seeker::tagPenalties

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