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

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

+ Inheritance diagram for FloodPath:
+ Collaboration diagram for FloodPath:

List of all members.

Public Member Functions

 FloodPath (Vector3 start, OnPathDelegate callbackDelegate)  Creates a new FloodPath instance.
override float CalculateStep (float remainingFrameTime)  Opens nodes until there are none left to search (or until the max time limit has been exceeded)

Detailed Description

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, floods it. This data will remain stored in the graph. 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 extreamly quicly.
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 it's 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 extreamly 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).
Warning:
Best to mention this early. When using this path, you should not call ANY OTHER PATHS (except FloodPathTracer) for it to work correctly. Though, if you are sure two areas will not connect to each other, you can actually call other paths in the other area, but be careful.
What could happen if another path is called in the same area as this one is that it overwrites the pathID and more importantly the data for the paths, which would render FloodPathTracer paths invalid, or in the worst case, get stuck in large loops and slow the game down a lot.
Sorry about the shouting, but hopefully I will not get the forums filled with threads about people using this path type alongside other path types now anyway.

Here follows some example code of the above list of steps:

public static FloodPath fpath;

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

When searching for a new path to someTargetPosition from let's say transform.position, you do

FloodPathTracer fpathTrace = new FloodPathTracer (transform.position,fpath,null);
seeker.StartPath (fpathTrace,OnPathComplete);

Where OnPathComplete is your callback function.

Note:
This path type relies on pathIDs being stored in the graph, but pathIDs are only 16 bits, meaning they will overflow after 65536 paths. When that happens all pathIDs in the graphs will be cleared, so at that point you will also need to recalculate the FloodPath.
To do so, register to the AstarPath::On65KOverflow callback:
public void Start () {
    AstarPath.On65KOverflow += MyCallbackFunction;
}

public void MyCallbackFunction () {
    //The callback is nulled every time it is called, so we need to register again
    AstarPath.On65KOverflow += MyCallbackFunction;
    
    //Recalculate the path
} 
This will happen after a very long time into the game, but it will happen eventually (look at the 'path number' value on the log messages when paths are completed for a hint about when)

Anothing 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
floodPathExample.png

Constructor & Destructor Documentation

FloodPath ( Vector3  start,
OnPathDelegate  callbackDelegate 
)

Creates a new FloodPath instance.


Member Function Documentation

override float CalculateStep ( float  remainingFrameTime) [virtual]

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

Reimplemented from Path.


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