Class FloodPath Extends Path

Public

Calculates paths from everywhere 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 calculate a FloodPathTracer path. That path will trace the path from its starting point all the way to where this path started. A FloodPathTracer search is extremely fast to calculate compared to a normal path request.

It is very useful in for example 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.

Usage:

  • At start, you calculate 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 the unit's position. It will then find the shortest path to the point specified when you calculated 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 calculate a new FloodPath and make all AIs calculate new FloodPathTracer paths.

Note

Since a FloodPathTracer path only uses precalculated information, it will always use the same penalties/tags as the FloodPath it references. If you want to use different penalties/tags, you will have to calculate a new FloodPath.

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 an NNConstraint on the FloodPathTracer, they must always inherit from FloodPathConstraint.
The easiest is to just modify the instance of FloodPathConstraint which is created as the default one.

Integration with the built-in movement scripts

The built-in movement scripts cannot calculate a FloodPathTracer path themselves, but you can use the SetPath method to assign such a path to them: var ai = GetComponent<IAstarAI>();
// Disable the agent's own path recalculation code
ai.canSearch = false;
ai.SetPath(FloodPathTracer.Construct(ai.position, floodPath));

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
OnVisitNode (pathNode, hScore, gScore)

Called for every node that the path visits.

Public

Public Static Methods

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

Public Variables

originalStartPoint
Public
saveParents

If false, will not save any information.

Public
startNode
Public
startPoint
Public

Public Static Variables

TemporaryNodeBit
Public Static

Inherited Public Members

BlockUntilCalculated ()

Blocks until this path has been calculated and returned.

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)

Increase the reference count on this path by 1 (for pooling).

Public
CompleteState

Current state of the path.

Public
Error ()

Aborts the path because of an error.

Public
FailWithError (msg)

Causes the path to fail and sets errorLog to msg.

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
IsDone ()

True if this path is done calculating.

Public
MarkerOpenCandidateConnectionsToEnd
Public Static Readonly
MarkerTrace
Public Static Readonly
OpenCandidateConnection (parentPathNode, targetPathNode, parentG, connectionCost, fractionAlongEdge, targetNodePosition)

Opens a connection between two nodes during the A* search.

Public
OpenCandidateConnectionBurst (pars, heap, heuristicObjective)

Burst-compiled internal implementation of OpenCandidateConnection.

Public Static
OpenCandidateConnectionsToEndNode (position, parentPathNode, parentNodeIndex, parentG)

Open a connection to the temporary end node if necessary.

Public
PipelineState

Returns the state of the path in the pathfinding pipeline.

Public
Release (o, silent=…)

Reduces the reference count on the path by 1 (pooling).

Public
ShouldConsiderPathNode (pathNodeIndex)

True if this path node might be worth exploring.

Public
UseSettings (settings)

Copies the given settings into this path.

Public
WaitForPath ()

Waits until this path has been calculated and returned.

Public
callback

Callback to call when the path is complete.

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
errorLog

Additional info on why a path failed.

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
nnConstraint

Constraint for how to search for nodes.

Public
path

Holds the path as a GraphNode list.

Public
pathID

ID of this path.

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

Private/Protected Members

AddStartNodesToHeap ()
Protected
CalculateStep (targetTick)

Calculates the path until completed or until the time has passed targetTick.

Protected
Cleanup ()

Always called after the path has been calculated.

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
FirstTemporaryEndNode ()
Protected
IsValid (nodeStorage)

Checks if the flood path data is still valid.

Internal
MarkNodesAdjacentToTemporaryEndNodes ()
Protected
OnEnterPool ()

Called when the path enters the pool.

Protected
OnFoundEndNode (pathNode, hScore, gScore)

Called when a valid node has been found for the end of the path.

Protected
OnHeapExhausted ()

Called when there are no more nodes to search.

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
TemporaryEndNodesBoundingBox (mn, mx)
Protected
Trace (fromPathNodeIndex)

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

Protected
ZeroTagPenalties

List of zeroes to use as default tag penalties.

Internal Static Readonly
completeState

Backing field for CompleteState.

Protected
hTargetNode

Target to use for H score calculation.

Protected
hasBeenReset

True if the Reset function has been called.

Protected
heuristicObjective

Target to use for H score calculations.

Protected
heuristicObjectiveInternal
Internal
internalTagPenalties

The tag penalties that are actually used.

Protected
parents
Protected
pathHandler

Data for the thread calculating this path.

Protected
validationHash
Private