Class AstarPath Extends VersionedMonoBehaviour

Public

Core component for the A* Pathfinding System.

This class handles all of the pathfinding system, calculates all paths and stores the info.
This class is a singleton class, meaning there should only exist at most one active instance of it in the scene.
It might be a bit hard to use directly, usually interfacing with the pathfinding system is done through the Seeker class.

Inner Types

Public Methods

AddWorkItem (callback)

Add a work item to be processed when pathfinding is paused.

Public
AddWorkItem (callback)

Add a work item to be processed when pathfinding is paused.

Public
AddWorkItem (item)

Add a work item to be processed when pathfinding is paused.

Public
AllocateNodes<T> (result, count, createNode, variantsPerNode)

Allocate a bunch of nodes at once.

Public
DrawGizmos ()

Calls OnDrawGizmos on graph generators.

Public
FlushGraphUpdates ()

Forces graph updates to complete in a single frame.

Public
FlushWorkItems ()

Forces work items to complete in a single frame.

Public
GetNearest (position)

Returns the nearest node to a position.

Public
GetNearest (position, constraint)

Returns the nearest node to a point using the specified NNConstraint.

Public
GetNearest (ray)

Returns the node closest to the ray (slow).

Public
GetTagNames ()

Returns tag names.

Public
LockGraphDataForReading ()

Allows you to access read-only graph data in jobs safely.

Public
LockGraphDataForWriting ()

Aquires an exclusive lock on the graph data asynchronously.

Public
LockGraphDataForWritingSync ()

Aquires an exclusive lock on the graph data.

Public
PausePathfinding ()

Blocks until all pathfinding threads are paused and blocked.

Public
QueueGraphUpdates ()

Will apply queued graph updates as soon as possible, regardless of batchGraphUpdates.

Public
Scan (graphToScan)

Scans a particular graph.

Public
Scan (graphsToScan=null)

Scans all specified graphs.

Public
ScanAsync (graphToScan)

Scans a particular graph asynchronously.

Public
ScanAsync (graphsToScan=null)

Scans all specified graphs asynchronously.

Public
UpdateGraphs (bounds, delay)

Update all graphs within bounds after delay seconds.

Public
UpdateGraphs (ob, delay)

Update all graphs using the GraphUpdateObject after delay seconds.

Public
UpdateGraphs (bounds)

Update all graphs within bounds.

Public
UpdateGraphs (ob)

Update all graphs using the GraphUpdateObject.

Public

Public Static Methods

BlockUntilCalculated (path)

Blocks until the path has been calculated.

Public Static
CalculateThreadCount (count)

Calculates number of threads to use.

Public Static
FindAstarPath ()

Used outside of play mode to initialize the AstarPath object even if it has not been selected in the inspector yet.

Public Static
FindTagNames ()

Tries to find an AstarPath object and return tag names.

Public Static
StartPath (path, pushToFront=…, assumeNotInPlayMode=…)

Adds the path to a queue so that it will be calculated as soon as possible.

Public Static

Public Variables

IsAnyGraphUpdateInProgress

Returns if any graph updates are being calculated right now.

Public
IsAnyGraphUpdateQueued

Returns if any graph updates are waiting to be applied.

Public
IsAnyWorkItemInProgress

Returns if any work items are in progress right now.

Public
IsUsingMultithreading

Returns whether or not multithreading is used.

Public
NumParallelThreads

Number of parallel pathfinders.

Public
batchGraphUpdates

Throttle graph updates and batch them to improve performance.

Public
colorSettings

Reference to the color settings for this AstarPath object.

Public
data

Holds all graph data.

Public
debugFloor

Low value to use for certain debugMode modes.

Public
debugMode

The mode to use for drawing nodes in the sceneview.

Public
debugPathData

The path to debug using gizmos.

Public
debugPathID

The path ID to debug using gizmos.

Public
debugRoof

High value to use for certain debugMode modes.

Public
euclideanEmbedding

Holds settings for heuristic optimization.

Public
fullGetNearestSearch

Do a full GetNearest search for all graphs.

Public
graphUpdateBatchingInterval

Minimum number of seconds between each batch of graph updates.

Public
graphs
Public
heuristic

The distance function to use as a heuristic.

Public
heuristicScale

The scale of the heuristic.

Public
isScanning

Set while any graphs are being scanned.

Public
lastScanTime

The time it took for the last call to Scan() to complete.

Public
logPathResults

The amount of debugging messages.

Public
manualDebugFloorRoof

If set, the debugFloor and debugRoof values will not be automatically recalculated.

Public
maxFrameTime

Max number of milliseconds to spend each frame for pathfinding.

Public
maxNearestNodeDistance

Maximum distance to search for nodes.

Public
maxNearestNodeDistanceSqr

Max Nearest Node Distance Squared.

Public
navmeshUpdates

Handles navmesh cuts.

offMeshLinks

Holds all active off-mesh links.

scanOnStartup

If true, all graphs will be scanned during Awake.

Public
showGraphs

Shows or hides graph inspectors.

Public
showNavGraphs

Visualize graphs in the scene view (editor only).

Public
showSearchTree

If enabled, nodes will draw a line to their 'parent'.

Public
showUnwalkableNodes

Toggle to show unwalkable nodes.

Public
threadCount

Number of pathfinding threads to use.

Public
unwalkableNodeDebugSize

Size of the red cubes shown in place of unwalkable nodes.

Public

Public Static Variables

Branch

Which branch of the A* Pathfinding Project is this release.

Public Static Readonly
Distribution

Used by the editor to guide the user to the correct place to download updates.

Public Static Readonly
On65KOverflow

Called when pathID overflows 65536 and resets back to zero.

Public Static
OnAwakeSettings

Called on Awake before anything else is done.

Public Static
OnGraphPostScan

Called for each graph after they have been scanned.

Public Static
OnGraphPreScan

Called for each graph before they are scanned.

Public Static
OnGraphsUpdated

Called when any graphs are updated.

Public Static
OnLatePostScan

Called after scanning has completed fully.

Public Static
OnPathPostSearch

Called for each path after searching.

Public Static
OnPathPreSearch

Called for each path before searching.

Public Static
OnPathsCalculated

Called right after callbacks on paths have been called.

Public Static
OnPostScan

Called after scanning.

Public Static
OnPreScan

Called before starting the scanning.

Public Static
Version

The version number for the A* Pathfinding Project.

Public Static Readonly
active

Returns the active AstarPath object in the scene.

Public Static

Public Enums

AstarDistribution

Information about where the package was downloaded.

Public

Private/Protected Members

AstarPath ()
Private
Awake ()
Protected
DelayedGraphUpdate ()

Waits a moment with updating graphs.

Private
DestroyNode (node)

Internal method to destroy a given node.

Internal
DirtyBounds (bounds)
Internal
GetNextPathID ()

Returns the next free path ID.

Internal
InitializeGraphs ()

Initializes the AstarData class.

Private
InitializeNode (node)

Initializes temporary path data for a node.

Internal
InitializeNodes (nodes)
Internal
InitializePathProcessor ()

Initializes the pathProcessor field.

Private
IsInsideWorkItem

Returns if this code is currently being exectuted inside a work item.

Internal
LogPathResults (path)

Prints path results to the log.

Private
NNConstraintNone

Cached NNConstraint.None to avoid unnecessary allocations.

Private Static Readonly
OnDestroy ()

Clears up variables and other stuff, destroys graphs.

Private
OnDisable ()

Cleans up graphs to avoid memory leaks.

Private
OnEnable ()

Called after this component is enabled.

Private
OnGUI ()

Draws the InGame debugging (if enabled)

Private
OnUpgradeSerializedData (migrations, unityThread)

Handle serialization backwards compatibility.

Protected
PausePathfindingSoon ()

Blocks the path queue so that e.g work items can be performed.

Internal
PerformBlockingActions (force=…)
Private
ProgressScanningIteratorsConcurrently (iterators, promises, async)
Internal Static
RecalculateDebugLimits ()
Private
Reset ()

Handle serialization backwards compatibility.

Protected
ScanInternal (graphsToScan, async)
Private
ShutdownPathfindingThreads ()
Private
Snapshot (bounds, graphMask)

Captures a snapshot of a part of the graphs, to allow restoring it later.

Internal
Update ()

Checks if any work items need to be executed then runs pathfinding for a while (if not using multithreading because then the calculation happens in other threads) and then returns any calculated paths to the scripts that requested them.

Private
UpdateGraphsInternal (ob, delay)

Update all graphs using the GraphUpdateObject after delay seconds.

Private
UpgradeSerializedData (isUnityThread)
Protected
VerifyIntegrity ()

Does simple error checking.

Internal
graphDataLock

Global read-write lock for graph data.

Private
graphUpdateRoutineRunning
Private
graphUpdates

Processes graph updates.

Private Readonly
graphUpdatesWorkItemAdded

Makes sure QueueGraphUpdates will not queue multiple graph update orders.

Private
hasScannedGraphAtStartup
Private
hierarchicalGraph

Holds a hierarchical graph to speed up some queries like if there is a path between two nodes.

Internal Readonly
inGameDebugPath

Debug string from the last completed path.

Private
isScanningBacking

Backing field for isScanning.

Private
lastGraphUpdate

Time the last graph update was done.

Private
nextFreePathID

The next unused Path ID.

Private
nodeStorage

Holds global node data that cannot be stored in individual graphs.

Internal
pathProcessor

Holds all paths waiting to be calculated and calculates them.

Private Readonly
pathReturnQueue

Holds all completed paths waiting to be returned to where they were requested.

Internal Readonly
redrawScope
Private
tagNames

Stored tag names.

Protected
waitForPathDepth
Private Static
workItemLock

Held if any work items are currently queued.

Private
workItems

Processes work items.

Private Readonly

Deprecated Members

prioritizeGraphs

Prioritize graphs.

Public
prioritizeGraphsLimit

Distance limit for prioritizeGraphs.

Public