A* Pathfinding Project  4.1.12
The A* Pathfinding Project for Unity 3D
NNConstraint Class Reference

Nearest node constraint. More...

Detailed Description

Nearest node constraint.

Constrains which nodes will be returned by the GetNearest function

Public Member Functions

 NNConstraint ()
 Default constructor. More...
 
virtual bool Suitable (GraphNode node)
 Returns whether or not the node conforms to this NNConstraint's rules. More...
 
virtual bool SuitableGraph (int graphIndex, NavGraph graph)
 Returns whether or not the graph conforms to this NNConstraint's rules. More...
 

Public Attributes

int area = -1
 Area ID to constrain to. More...
 
bool constrainArea
 Only treat nodes in the area area as suitable. More...
 
bool constrainDistance = true
 Constrain distance to node. More...
 
bool constrainTags = true
 Sets if tags should be constrained. More...
 
bool constrainWalkability = true
 Constrain the search to only walkable or unwalkable nodes depending on walkable. More...
 
bool distanceXZ
 if available, do an XZ check instead of checking on all axes. More...
 
int graphMask = -1
 Graphs treated as valid to search on. More...
 
int tags = -1
 Nodes which have any of these tags set are suitable. More...
 
bool walkable = true
 Only search for walkable or unwalkable nodes if constrainWalkability is enabled. More...
 

Properties

static NNConstraint Default [get]
 The default NNConstraint. More...
 
static NNConstraint None [get]
 Returns a constraint which does not filter the results. More...
 

Constructor & Destructor Documentation

◆ NNConstraint()

Default constructor.

Equals to the property Default

Member Function Documentation

◆ Suitable()

virtual bool Suitable ( GraphNode  node)
virtual

Returns whether or not the node conforms to this NNConstraint's rules.

Reimplemented in FloodPathConstraint.

◆ SuitableGraph()

virtual bool SuitableGraph ( int  graphIndex,
NavGraph  graph 
)
virtual

Returns whether or not the graph conforms to this NNConstraint's rules.

Note that only the first 31 graphs are considered using this function. If the graphMask has bit 31 set (i.e the last graph possible to fit in the mask), all graphs above index 31 will also be considered suitable.

Member Data Documentation

◆ area

int area = -1

Area ID to constrain to.

Will not affect anything if less than 0 (zero) or if constrainArea is false

◆ constrainArea

bool constrainArea

Only treat nodes in the area area as suitable.

Does not affect anything if area is less than 0 (zero)

◆ constrainDistance

bool constrainDistance = true

Constrain distance to node.

Uses distance from AstarPath.maxNearestNodeDistance. If this is false, it will completely ignore the distance limit.

If there are no suitable nodes within the distance limit then the search will terminate with a null node as a result.

Note
This value is not used in this class, it is used by the AstarPath.GetNearest function.

◆ constrainTags

bool constrainTags = true

Sets if tags should be constrained.

See also
tags

◆ constrainWalkability

bool constrainWalkability = true

Constrain the search to only walkable or unwalkable nodes depending on walkable.

◆ distanceXZ

bool distanceXZ

if available, do an XZ check instead of checking on all axes.

The navmesh/recast graph supports this.

This can be important on sloped surfaces. See the image below in which the closest point for each blue point is queried for:

The navmesh/recast graphs also contain a global option for this: nearestSearchOnlyXZ.

◆ graphMask

int graphMask = -1

Graphs treated as valid to search on.

This is a bitmask meaning that bit 0 specifies whether or not the first graph in the graphs list should be able to be included in the search, bit 1 specifies whether or not the second graph should be included and so on.

// Enables the first and third graphs to be included, but not the rest
myNNConstraint.graphMask = (1 << 0) | (1 << 2);
Note
This does only affect which nodes are returned from a GetNearest call, if a valid graph is connected to an invalid graph using a node link then it might be searched anyway.
See also
AstarPath.GetNearest
SuitableGraph
Bitmask Tutorial

◆ tags

int tags = -1

Nodes which have any of these tags set are suitable.

This is a bitmask, i.e bit 0 indicates that tag 0 is good, bit 3 indicates tag 3 is good etc.

See also
constrainTags
graphMask
Bitmask Tutorial

◆ walkable

bool walkable = true

Only search for walkable or unwalkable nodes if constrainWalkability is enabled.

If true, only walkable nodes will be searched for, otherwise only unwalkable nodes will be searched for. Does not affect anything if constrainWalkability if false.

Property Documentation

◆ Default

NNConstraint Default
staticget

The default NNConstraint.

Equivalent to new NNConstraint (). This NNConstraint has settings which works for most, it only finds walkable nodes and it constrains distance set by A* Inspector -> Settings -> Max Nearest Node Distance

◆ None

NNConstraint None
staticget

Returns a constraint which does not filter the results.


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