Class FloodPath Extends Path

Public

Floods the area completely for easy computation of any path to a single point.

This path is a bit special, because it does not do anything useful by itself. What it does is that it calculates paths to all nodes it can reach, it floods the graph. This data will remain stored in the path. Then you can call a FloodPathTracer path, that path will trace the path from it's starting point all the way to where this path started flooding and thus generating a path extremely quickly.
It is very useful in for example TD (Tower Defence) games where all your AIs will walk to the same point, but from different places, and you do not update the graph or change the target point very often, what changes is their positions and new AIs spawn all the time (which makes it hard to use the MultiTargetPath).
With this path type, it can all be handled easily.

  • At start, you simply start ONE FloodPath and save the reference (it will be needed later).

  • Then when a unit is spawned or needs its path recalculated, start a FloodPathTracer path from it's position. It will then find the shortest path to the point specified when you called the FloodPath extremely quickly.

  • If you update the graph (for example place a tower in a TD game) or need to change the target point, you simply call a new FloodPath (and store it's reference).

Version

From 3.2 and up, path traversal data is now stored in the path class. So you can now use other path types in parallel with this one.

Here follows some example code of the above list of steps: public static FloodPath fpath;

public void Start () {
fpath = FloodPath.Construct (someTargetPosition, null);
AstarPath.StartPath (fpath);
}

When searching for a new path to someTargetPosition from let's say transform.position, you do FloodPathTracer fpathTrace = FloodPathTracer.Construct (transform.position,fpath,null);
seeker.StartPath (fpathTrace,OnPathComplete);
Where OnPathComplete is your callback function.
Another thing to note is that if you are using NNConstraints on the FloodPathTracer, they must always inherit from Pathfinding.PathIDConstraint.
The easiest is to just modify the instance of PathIDConstraint which is created as the default one.

A* Pro Feature:

This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited.
The Pro version can be bought here

Public Methods

FloodPath ()

Default constructor.

Public
GetParent (node)
Public
HasPathTo (node)
Public

Public Static Methods

Construct (start, callback=null)
Public Static
Construct (start, callback=null)
Public Static

Public Variables

FloodingPath
Public
originalStartPoint
Public
saveParents

If false, will not save any information.

Public
startNode
Public
startPoint
Public

Inherited Public Members

BlockUntilCalculated ()

Blocks until this path has been calculated and returned.

Public
callback

Callback to call when the path is complete.

Public
CanTraverse (node)

Returns if the node can be traversed.

Public
CanTraverse (from, to)

Returns if the path can traverse a link between from and to and if to can be traversed itself.

Public
Claim (o)

Claim this path (pooling).

Public
CompleteState

Current state of the path.

Public
duration

How long it took to calculate this path in milliseconds.

Public
enabledTags

Which graph tags are traversable.

Public
error

If the path failed, this is true.

Public
Error ()

Aborts the path because of an error.

Public
errorLog

Additional info on why a path failed.

Public
FailWithError (msg)

Causes the path to fail and sets errorLog to msg.

Public
FloodingPath

True for paths that want to search all nodes and not jump over nodes as optimizations.

Public
GetConnectionSpecialCost (a, b, currentCost)

May be called by graph nodes to get a special cost for some connections.

Public
GetTagPenalty (tag)

Returns penalty for the given tag.

Public
GetTotalLength ()

Total Length of the path.

Public
GetTraversalCost (node)

Returns the cost of traversing the given node.

Public
heuristic

Determines which heuristic to use.

Public
heuristicScale

Scale of the heuristic values.

Public
immediateCallback

Immediate callback to call when the path is complete.

Public
IsDone ()

Returns if this path is done calculating.

Public
nnConstraint

Constraint for how to search for nodes.

Public
path

Holds the path as a Node array.

Public
pathID

ID of this path.

Public
PipelineState

Returns the state of the path in the pathfinding pipeline.

Public
Release (o, silent=…)

Releases a path claim (pooling).

Public
searchedNodes

Number of nodes this path has searched.

Public
tagPenalties

Penalties for each tag.

Public
traversalProvider

Provides additional traversal information to a path request.

Public
vectorPath

Holds the (possibly post processed) path as a Vector3 list.

Public
WaitForPath ()

Waits until this path has been calculated and returned.

Public

Private/Protected Members

CalculateHScore (node)

Estimated cost from the specified node to the target.

Package
CalculateStep (targetTick)

Opens nodes until there are none left to search (or until the max time limit has been exceeded)

Protected
Cleanup ()

Always called after the path has been calculated.

Protected
completeState

Backing field for CompleteState.

Protected
currentR

The node currently being processed.

Protected
DebugString (logMode)

Returns a string with information about it.

Protected
DebugStringPrefix (logMode, text)

Writes text shared for all overrides of DebugString to the string builder.

Protected
DebugStringSuffix (logMode, text)

Writes text shared for all overrides of DebugString to the string builder.

Protected
GetHTarget ()
Protected
hasBeenReset

True if the Reset function has been called.

Protected
hTarget

Target to use for H score calculations.

Protected
hTargetNode

Target to use for H score calculation.

Protected
Initialize ()

Initializes the path.

Protected
internalTagPenalties

The tag penalties that are actually used.

Protected
manualTagPenalties

Tag penalties set by other scripts.

Protected
next

Internal linked list implementation.

Package
OnEnterPool ()

Called when the path enters the pool.

Protected
parents
Protected
pathHandler

Data for the thread calculating this path.

Protected
Prepare ()

Called before the path is started.

Protected
PrepareBase (pathHandler)

Prepares low level path variables for calculation.

Protected
Reset ()

Reset all values to their default values.

Protected
ReturnPath ()

Calls callback to return the calculated path.

Protected
Setup (start, callback)
Protected
Setup (start, callback)
Protected
Trace (from)

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

Protected
ZeroTagPenalties

List of zeroes to use as default tag penalties.

Package Static Readonly