Struct NearestNodeConstraint

Public

Constraint for the AstarPath.GetNearest method.

This is used to filter out nodes you are not interested in.

For example, you can use this to only find walkable nodes, or only nodes with a specific tag.

Why is this struct passed around with the ref keyword all the time?

Structs are passed by value in C#, and copying them can be expensive when they are large (like this one at around 44 bytes). Using the ref keyword allows it to be passed by reference instead, which is much faster.

But then why is it not a class?

Firstly, because classes involve the garbage collector, and since this struct is created very often (often many times per frame), we want to avoid that. Garbage collections are very expensive operations, and can cause stuttering in the game.

Public Methods

Suitable (node)

True if the node is ok with respect to the constraints set in this struct.

Public Variables

allNodesAreSuitable

True if all nodes are suitable with respect to the constraints set in this struct.

Public
area

Area ID to constrain to.

Public
distanceMetric

Determines how to measure distances to the navmesh.

Public
filter

Allow only nodes which the given filter function returns true for.

Public
graphMask

Graphs which are traversable.

Public
maxDistance

The maximum distance to the navmesh to search before the search fails.

Public
maxDistanceSqr

Squared maxDistance.

Public
tags

Set of tags which are traversable.

Public
traversalProvider

Allow traversing only nodes that are also traversable by the given ITraversalProvider.

Public
walkable

Constraint to only search only walkable nodes, only unwalkable nodes, or both.

Public

Public Static Variables

None

Constraint which allows all nodes.

Public Static Readonly
Walkable

Constraint which filters out all unwalkable nodes.

Public Static Readonly

Public Enums

WalkabilityConstraint
Public

Private/Protected Members

traversal

Sub-filter with more constraints.

Internal