Version: 5.5 (switch to 5.6b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NavMeshAgent

class in UnityEngine.AI

/

Inherits from:Behaviour

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Navigation mesh agent.

This component is attached to a mobile character in the game to allow it to navigate the scene using the NavMesh. See the Navigation section of the manual for further details.

Variables

accelerationThe maximum acceleration of an agent as it follows a path, given in units / sec^2.
angularSpeedMaximum turning speed in (deg/s) while following a path.
areaMaskSpecifies which NavMesh areas are passable. Changing areaMask will make the path stale (see isPathStale).
autoBrakingShould the agent brake automatically to avoid overshooting the destination point?
autoRepathShould the agent attempt to acquire a new path if the existing path becomes invalid?
autoTraverseOffMeshLinkShould the agent move across OffMeshLinks automatically?
avoidancePriorityThe avoidance priority level.
baseOffsetThe relative vertical displacement of the owning GameObject.
currentOffMeshLinkDataThe current OffMeshLinkData.
desiredVelocityThe desired velocity of the agent including any potential contribution from avoidance. (Read Only)
destinationGets or attempts to set the destination of the agent in world-space units.
hasPathDoes the agent currently have a path? (Read Only)
heightThe height of the agent for purposes of passing under obstacles, etc.
isOnNavMeshIs the agent currently bound to the navmesh? (Read Only)
isOnOffMeshLinkIs the agent currently positioned on an OffMeshLink? (Read Only)
isPathStaleIs the current path stale. (Read Only)
nextOffMeshLinkDataThe next OffMeshLinkData on the current path.
nextPositionGets or sets the simulation position of the navmesh agent.
obstacleAvoidanceTypeThe level of quality of avoidance.
pathProperty to get and set the current path.
pathPendingIs a path in the process of being computed but not yet ready? (Read Only)
pathStatusThe status of the current path (complete, partial or invalid).
radiusThe avoidance radius for the agent.
remainingDistanceThe distance between the agent's position and the destination on the current path. (Read Only)
speedMaximum movement speed when following a path.
steeringTargetGet the current steering target along the path. (Read Only)
stoppingDistanceStop within this distance from the target position.
updatePositionGets or sets whether the transform position is synchronized with the simulated agent position. The default value is true.
updateRotationShould the agent update the transform orientation?
velocityAccess the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.

Public Functions

ActivateCurrentOffMeshLinkEnables or disables the current off-mesh link.
CalculatePathCalculate a path to a specified point and store the resulting path.
CompleteOffMeshLinkCompletes the movement on the current OffMeshLink.
FindClosestEdgeLocate the closest NavMesh edge.
GetAreaCostGets the cost for path calculation when crossing area of a particular type.
MoveApply relative movement to current position.
RaycastTrace a straight path towards a target postion in the NavMesh without moving the agent.
ResetPathClears the current path.
ResumeResumes the movement along the current path after a pause.
SamplePathPositionSample a position along the current path.
SetAreaCostSets the cost for traversing over areas of the area type.
SetDestinationSets or updates the destination thus triggering the calculation for a new path.
SetPathAssign a new path to this agent.
StopStop movement of this agent along its current path.
WarpWarps agent to the provided position.

Inherited members

Variables

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledHas the Behaviour had enabled called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Functions

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Static Functions

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.