Class MultiTargetPath
Extends
ABPath
Public
A path which searches from one point to a number of different targets in one search or from a number of different start points to a single target.
This is faster than searching with an ABPath for each target if pathsForAll is true. This path type can be used for example when you want an agent to find the closest target of a few different options.
When pathsForAll is true, it will calculate a path to each target point, but it can share a lot of calculations for the different paths so it is faster than requesting them separately.
When pathsForAll is false, it will perform a search using the heuristic set to None and stop as soon as it finds the first target. This may be faster or slower than requesting each path separately. It will run a Dijkstra search where it searches all nodes around the start point until the closest target is found. Note that this is usually faster if some target points are very close to the start point and some are very far away, but it can be slower if all target points are relatively far away because then it will have to search a much larger region since it will not use any heuristics.
A* Pro FeatureThis 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
VersionSince 3.7.1 the vectorPath and path fields are always set to the shortest path even when pathsForAll is true.
Public Methods
Public Variables
Callbacks to call for each individual path.
int
chosenTarget = -1
The closest target index (if any target was found)
bool
endPointKnownBeforeCalculation
True if this path type has a well defined end point, even before calculation starts.
This is for example true for the ABPath type, but false for the RandomPath type.
bool
inverted
False if the path goes from one point to multiple targets.
True if it goes from multiple start points to one target point
Stores all paths to the targets.
Elements are null if no path was found
Vector3[]
originalTargetPoints
Target points specified when creating the path.
These are not snapped to the nearest nodes
bool
pathsForAll = true
If true, a path to all targets will be returned, otherwise just the one to the closest one.
uint[]
targetPathCosts
The cost of the calculated path for each target.
Will be 0 if a path was not found.
Vector3[]
targetPoints
Target points specified when creating the path.
These are snapped to the nearest nodes
bool[]
targetsFound
Indicates if the target has been found.
Also true if the target cannot be reached (is in another area)
List<Vector3 >[]
vectorPaths
Stores all vector paths to the targets.
Elements are null if no path was found
Inherited Public Members
Current state of the path.
Unity.Profiling.ProfilerMarker
MarkerOpenCandidateConnectionsToEnd = new Unity.Profiling.ProfilerMarker("OpenCandidateConnectionsToEnd")
Unity.Profiling.ProfilerMarker
MarkerTrace = new Unity.Profiling.ProfilerMarker("Trace")
Returns the state of the path in the pathfinding pipeline.
bool
calculatePartial
Calculate partial path if the target node cannot be reached.
If the target node cannot be reached, the node which was closest (given by heuristic) will be chosen as target node and a partial path will be returned. This only works if a heuristic is used (which is the default). If a partial path is found, CompleteState is set to Partial.
NoteIt is not required by other path types to respect this setting
The endNode and endPoint will be modified and be set to the node which ends up being closest to the target.
WarningUsing this may make path calculations significantly slower if you have a big graph. The reason is that when the target node cannot be reached, the path must search through every single other node that it can reach in order to determine which one is closest. This may be expensive, and is why this option is disabled by default.
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
uint
cost
Total cost of this path as used by the pathfinding algorithm.
The cost is influenced by both the length of the path, as well as any tags or penalties on the nodes. By default, the cost to move 1 world unit is Int3.Precision.
If the path failed, the cost will be set to zero.
float
duration
How long it took to calculate this path in milliseconds.
bool
endPointKnownBeforeCalculation
True if this path type has a well defined end point, even before calculation starts.
This is for example true for the ABPath type, but false for the RandomPath type.
Optional ending condition for the path.
The ending condition determines when the path has been completed. Can be used to for example mark a path as complete when it is within a specific distance from the target.
If ending conditions are used that are not centered around the endpoint of the path, then you should also set the heuristic to None to ensure the path is still optimal. The performance impact of setting the heuristic to None is quite large, so you might want to try to run it with the default heuristic to see if the path is good enough for your use case anyway.
If null, no custom ending condition will be used. This means that the path will end when the target node has been reached.
NoteIf the ending condition returns false for all nodes, the path will just keep searching until it has searched the whole graph. This can be slow.
bool
error
If the path failed, this is true.
This typically happens if there's no valid node close enough to the start point of the path, or if there's no node close enough to the target point that is reachable from the start point. The errorLog will have more information about what happened.
string
errorLog
Additional info on why a path failed.
Determines which heuristic to use.
float
heuristicScale = 1F
Scale of the heuristic values.
Constraint for how to search for nodes that are traversable by this path.
This constraint is what the path uses to search for closest nodes to the start and end points.
This is derived from the traversalConstraint and the nearestNodeDistanceMetric.
Distance metric to use when searching for the start and end nodes in the graph.
By default, the euclidean distance metric is used. This allows the path to, for example, find the closest start node to the start point, as measured using "normal" distance. However, you can change this to instead measure distance by ignoring the Y coordinate. This is quite useful for characters, as it will find the node right below the agents feet, even if the agent is slightly above the ground on a slope.
Vector3
originalEndPoint
End Point exactly as in the path request.
Vector3
originalStartPoint
Start Point exactly as in the path request.
Holds the path as a GraphNode list.
These are all nodes that the path traversed, as calculated by the pathfinding algorithm. This may not be the same nodes as the post processed path traverses.
ushort
pathID
ID of this path.
Used to distinguish between different paths
int
searchedNodes
Number of nodes this path has searched.
Constrains which nodes the path can traverse.
By default, all walkable nodes are traversable. But you can modify this to, for example, only allow nodes with a certain tag to be traversed, or supply completely custom rules by using an ITraversalProvider.
Specifies the cost of traversing different nodes.
By default, nodes have no special costs associated with them. But you can modify this to, for example, make nodes with a certain tag more expensive to traverse, or supply completely custom rules by using an ITraversalProvider.
List<Vector3>
vectorPath
Holds the (possibly post-processed) path as a Vector3 list.
This list may be modified by path modifiers to be smoother or simpler compared to the raw path generated by the pathfinding algorithm.
Private/Protected Members
bool
hasBeenReset
True if the Reset function has been called.
Used to alert users when they are doing something wrong.
bool
hasEndPoint
Determines if a search for an end node should be done.
Set by different path types.
uint
partialBestTargetGScore = uint.MaxValue
uint
partialBestTargetHScore = uint.MaxValue
Current best target for the partial path.
This is the node with the lowest H score.
int
targetNodeCount
Number of target nodes left to find.