Skip to content

Nav3DAgent

Nav3DAgent is the main class responsible for moving game agents through the scene. Its public methods can only be used after Nav 3D has been initialized. Use it as a component on your game units. Its parameters live in a separate container, Nav3DAgentConfig.

  • public static Nav3DAgent[] GetAgentsInBounds(Bounds _Bounds) — all agents inside the Bounds.
  • public static Nav3DAgent[] GetAgentsInSphere(Vector3 _Center, float _Radius) — all agents inside the sphere.

Nav3DAgentConfig stores an agent’s parameters. Create an instance via the Project tab context menu. Its inspector groups the parameters as follows.

Upgrading rotation settings. After updating Nav 3D or importing an older Nav3DAgentConfig, the editor automatically converts and saves writable config assets under Assets, including binary assets. The old degrees-per-tick value is divided by the project’s current Fixed Timestep: 5 degrees/tick at 0.02 s becomes 250 degrees/s; zero stays zero. Wait for migration to finish before changing Fixed Timestep. You can run Tools ▸ Nav3D ▸ Upgrade Agent Configs to finish or retry it manually; a build checks that migration was saved. For a read-only asset or a config in a package, copy it into a writable Assets folder and assign that copy to your agents. Resolve any migration error in the Console before building.

Nav3DAgentConfig (1)

After creating a config instance, in its inspector you will see the following list of parameter groups:

Nav3DAgentConfig (2)

Nav3DAgentConfig inspector parameter groups.

Option Property Type Description Range
Radius
Radius Radius float The agent radius used for local avoidance. Set it so the visual content of the unit fits inside the sphere of this radius. >0
Movement
Control mode [NEW in 3.1.0] ControlMode enum Who moves the agent’s transform: NAV3D, the agent itself, or EXTERNAL, your own controller using DesiredVelocity (see “External Control”). Changed on a live agent, it takes effect at the next SetConfig. NAV3D, EXTERNAL
Motion mode [NEW in 3.0.0] MotionMode enum How the agent’s speed evolves along the path; see the “Motion modes” chapter. CONSTANT, EASED, ACCELERATED, FLIGHT
Section anchoring [NEW in 3.0.0] EaseAnchoring enum EASED: how the start/final section extents are interpreted. ABSOLUTE_LENGTH, PATH_FRACTION
Start section [NEW in 3.0.0] EaseStartSection float EASED: extent of the ramp-up section (units or path fraction). ≥ 0
Final section [NEW in 3.0.0] EaseFinalSection float EASED: extent of the braking section (units or path fraction). ≥ 0
Start ease curve [NEW in 3.0.0] EaseStartCurve AnimationCurve EASED: the speed shape over the start section. 0..1
Final ease curve [NEW in 3.0.0] EaseFinalCurve AnimationCurve EASED: the speed shape over the final section. 0..1
Acceleration (u/s²) [NEW in 3.0.0] Acceleration float ACCELERATED/FLIGHT: acceleration in units/second² (0 = instant). With local avoidance it also limits how sharply velocity may change while avoiding (0 = unlimited). ≥ 0
Deceleration (u/s², 0 = same as acceleration) [NEW in 3.0.0] Deceleration float ACCELERATED: the braking rate in units/second²; 0 = use Acceleration. The rate actually in force is the read-only DecelerationEffective, which reports AccelerationEffective while this is 0. ≥ 0
Max lateral acceleration (u/s²) [NEW in 3.0.0] FlightMaxLateralAcceleration float FLIGHT: the turn budget in units/second². > 0
Max path deviation (units) [NEW in 3.0.0] FlightMaxDeviation float FLIGHT: allowed swing-out from the found path, world units. ≥ 0
Max bank angle (degrees) [NEW in 3.0.0] FlightBankAngleMax float FLIGHT: the visual roll limit, degrees. ≥ 0
Bank responsiveness (1/s) [NEW in 3.0.0] FlightBankResponsiveness float FLIGHT: how quickly the roll follows the turn rate, 1/second. > 0
Speed (units/second) Speed float The agent speed in world units per second. Can be changed at any time. >0
Max speed (units/second) MaxSpeed float Maximum speed in units per second used during local avoidance (the agent may exceed Speed while maneuvering). The ceiling actually in force is the read-only FactualMaxSpeed: MaxSpeed while local avoidance is enabled, and plain Speed while it is not. >Speed
Target reach distance TargetReachDistance float Distance at which the target is considered reached (e.g. agent radius + target radius). >=0
Rotation ▸ Max rotation in degrees per second MaxAgentDegreesRotationPerSecond float Maximum turn toward velocity in degrees/s. Default: 250; zero disables rotation. Independent of Fixed Timestep. >=0
Rotation ▸ Rotation vector lerp factor RotationVectorLerpFactor float Smooths the desired rotation direction per physics tick. Lower is smoother, higher is sharper. Smoothing depends on Fixed Timestep. 0 - 1
Local avoidance
Local avoidance enabled [NEW in 3.0.0] LocalAvoidanceEnabled bool Whether the agent performs local avoidance of nearby agents and obstacles while following its path. Replaces the removed MotionNavigationType (COMBINED = enabled, GLOBAL = disabled). true, false
Avoid static obstacles AvoidStaticObstacles bool Whether to perform local avoidance against obstacles. Affects performance; enable only when necessary. true, false
Advanced ▸ Avoidance lookahead (body widths) [NEW in 3.0.0] AvoidanceLookahead float How far ahead the agent starts avoiding, in combined body widths; the horizon in seconds is derived per encounter from both bodies’ sizes and speeds. A pair negotiates on the smaller of the two lookaheads. ≥ 0
Advanced ▸ Certified clearance gate [NEW in 3.0.0] CertifiedClearanceGate bool Static-obstacle avoidance constraints stand down while the agent rides a path certified clear for its radius (see “Certified clearance”). Effective with volumetric pathfinding, local avoidance and Avoid static obstacles all enabled. true, false
Advanced ▸ Avoidance aggressiveness [NEW in 3.0.0] AvoidanceAggressiveness float 1 = the pure avoidance solution and its collision-free guarantee; lower values blend toward the raw path velocity for softer maneuvers without the guarantee. 0..1
Advanced ▸ Avoidance priority [NEW in 3.0.0] AvoidancePriority float How strongly the agent’s size counts when a meeting pair splits its avoidance manoeuvre (weight = Radius × priority; the smaller weight does more of the moving). 1 = size alone; 0 = always gives way. ≥ 0
Pathfinding
Pathfinding mode (Point / Volumetric) [NEW in 3.0.0] RadiusAwarePathfinding bool Enables volumetric (agent-radius-aware) pathfinding: the path keeps the agent radius clear of obstacles and refuses passages narrower than the agent. true, false
On too-narrow space [NEW in 3.0.0] VolumetricMode enum What to do when no corridor wide enough for the agent exists: fail honestly, or deliver a classic point path flagged as degraded. STRICT, FALLBACK_TO_DEFAULT
Optimality [NEW in 3.1.0] Optimality enum FAST for a fast search, QUALITY (the default) for a quality route, HIGH_QUALITY for a still shorter one; the better the route, the costlier the search. See “Optimality” in “Volumetric pathfinding”. FAST, QUALITY, HIGH_QUALITY
Pathfinding radius scale [NEW in 3.0.0] PathfindingRadiusScale float Multiplier over Radius for the pathfinding clearance (does not affect the local-avoidance radius). >0
Pathfinding timeout (ms) PathfindingTimeout int Maximum time allowed for pathfinding; what a timeout does is set by On timeout. >0
On timeout [NEW in 3.0.0] TimeoutMode enum What to do when the timeout passes after a complete route was already found: deliver it, flagged as timed out (Nav3DPath.IsTimedOut), or fail the order with TIMEOUT and the _OnPathfindingFail callback. A timeout with no complete route found always fails. DELIVER_FOUND_ROUTE, FAIL
Smooth the path SmoothPath bool Whether to smooth the found path. true, false
Samples per min bucket volume SmoothRatio int Path segments per minimum octree cell produced by smoothing. Do not increase excessively. >0
Auto-update path on stagnant behavior AutoUpdatePath bool Re-find the path from the agent’s current position when it has drifted far from its path (e.g. while avoiding crowds). true, false
Auto-update cooldown (ms) PathAutoUpdateCooldown int Minimum path auto-update period; limit it to a few seconds to protect performance. >=1
Advanced ▸ Try reposition start if occupied [NEW in 3.1.0] TryRepositionStartIfOccupied bool If the agent’s start is inside an obstacle, start from the nearest free point outside it; otherwise pathfinding fails with START_POINT_INSIDE_OBSTACLE. On by default. true, false
Advanced ▸ Try reposition target if occupied TryRepositionTargetIfOccupied bool If the target is inside an obstacle, path to the nearest free point outside it and stop there; otherwise pathfinding fails with TARGET_POINT_INSIDE_OBSTACLE. On by default. true, false
Debug
Use Log UseLog bool Whether to log the agent’s work processes. true, false
Log records count LogSize int Agent log size. >0

Local avoidance:

With local avoidance enabled, the agent solves one avoidance program (ORCA) over the nearby agents and obstacle triangles every tick and follows the resulting velocity directly — there are no blending weights to tune anymore. Avoid static obstacles (default on) is what puts the nearby obstacle surfaces into that program; it acts only while the agent uses volumetric pathfinding (Pathfinding ▸ Pathfinding mode), because a point path keeps no clearance for the body — with point pathfinding the agent avoids other agents only, and the distance kept from geometry is the search’s job.

AvoidanceAggressiveness (0..1, default 1) is the single “feel” control: 1 = the pure avoidance solution and its collision-free guarantee; lower values blend toward the raw path velocity — softer maneuvers, without the guarantee. New in 3.0.0

Acceleration (units/second², 0 = unlimited) additionally limits how sharply the agent may change velocity while avoiding. New in 3.0.0

Avoidance lookahead (body widths, default 2) sets how far ahead the agent starts avoiding, in combined body widths; the horizon in seconds is derived per encounter from both bodies’ sizes and speeds. A pair negotiates on the smaller of the two lookaheads. Raise it for earlier, smoother avoidance; lower it for later, sharper swerves. New in 3.0.0

Avoidance priority (default 1) weights how a meeting pair splits its avoidance manoeuvre: each body’s weight is Radius × priority, and each does the portion of the manoeuvre proportional to the OTHER’s weight — the smaller weight moves more. Raise it for a body that should hold its line; 0 = always gives way entirely. New in 3.0.0

Certified clearance gate (on by default) lets the static-obstacle constraints stand down while the agent rides a path certified clear for its radius — see “Certified clearance” in the “Volumetric pathfinding” chapter. New in 3.0.0

Creating and configuring a config via code

Section titled “Creating and configuring a config via code”
  • Use Nav3DAgentConfig.DefaultConfig to create a new instance.
  • Use Copy() to clone an instance.
  • Apply a config with Nav3DAgent.SetConfig(Nav3DAgentConfig _Config).
void ConfigureAgentConfig()
{
Nav3DAgent myAgent = GetComponent<Nav3DAgent>();
Nav3DAgentConfig myConfig = Nav3DAgentConfig.DefaultConfig;
myConfig.Radius = 1.2f;
myConfig.LocalAvoidanceEnabled = true;
myAgent.SetConfig(myConfig.Copy());
}
  • event Action<PathfindingResult> OnPathUpdated — fires whenever an agent’s path is updated (by a user command or by any Nav 3D subsystem).
  • event Action<Vector3> OnDesiredVelocityUpdated — raised every physics tick with DesiredVelocity, after every agent has computed its velocity; see “External Control”.
  • public void SetConfig(Nav3DAgentConfig _Config) — replaces the config and stops the current command (MoveTo, MoveToPoints, FollowTarget); give the agent a new one after the call.

public void MoveTo(Vector3 _Point, Action _OnReach = null, Action _OnPathReady = null, Action<PathfindingResult> _OnPathfindingFail = null, float? _ReachDistance = null, bool _InterruptCurrentOrderImmediate = false) — begins movement to a point.

  • _Point — target point.
  • _OnReach — invoked when the target is reached.
  • _OnPathReady — invoked when pathfinding finished successfully.
  • _OnPathfindingFail — pathfinding failure callback.
  • _ReachDistance — target reach distance.
  • _InterruptCurrentOrderImmediate — whether to stop the current order immediately.

public void MoveToPoints(Vector3[] _Points, bool _Loop = false, bool _StartFromClosest = false, bool _SkipUnpassableTargets = false, float? _ReachDistance = null, Action<Vector3> _OnTargetPassed = null, Action _OnFinished = null, Action _OnPathReady = null, Action<PathfindingResult> _OnPathfindingFail = null, bool _InterruptCurrentOrderImmediate = false, Action<int> _OnTargetIndexPassed = null) — moves through a set of points sequentially.

  • _Points — target points.
  • _Loop — loop movement through the points.
  • _StartFromClosest — start from the nearest point instead of the first.
  • _SkipUnpassableTargets — skip points pathfinding to which failed; if disabled a failure aborts and calls _OnFail.
  • _ReachDistance — reach distance for any target point.
  • _OnTargetPassed — reports a position from the followed trajectory. Inserted, repositioned or projected points and replans can produce coordinate callbacks; use _OnTargetIndexPassed to identify authored waypoints for gameplay.
  • _OnTargetIndexPassed — optional Action<int> reporting the passed point’s original index in _Points, once per pass and again on each loop lap. Indices are not renumbered for StartFromClosest or replanning. Engine-inserted starts/loop closure points and skipped targets are never reported. An explicit closing duplicate supplied in _Points retains its own input index. Adjacent equal inputs are trimmed, so only retained waypoints report a pass. The coordinate callback remains available separately. New in 3.1.0
  • _OnFinished — invoked when the last target is reached (never if _Loop = true).
  • _OnPathReady / _OnPathfindingFail / _InterruptCurrentOrderImmediate — as above.

public void FollowTarget(Transform _Target, bool _FollowContinuously = false, float _TargetOffsetUpdate = 0.1f, float _TargetReachDistance = 0, Action _OnReach = null, Action _OnFail = null, Action _OnPathReady = null, Action<PathfindingResult> _OnPathfindingFail = null, bool _InterruptCurrentOrderImmediate = false) — follows a moving transform target.

  • _Target — transform to follow.
  • _FollowContinuously — follow indefinitely; the agent waits at the target instead of finishing.
  • _TargetOffsetUpdate — minimum target movement that triggers a path update.
  • _TargetReachDistance — distance required to finish following and call _OnReach.
  • _OnReach — on reach callback.
  • _OnFail — invoked if the target is destroyed or deactivated.
  • _OnPathReady / _OnPathfindingFail / _InterruptCurrentOrderImmediate — as above.
  • public void Stop() — stops the current command (MoveTo, MoveToPoints, FollowTarget).
  • public void SetStateSource(INav3DAgentStateSource _Source) — sets where an agent under External Control reads its transform’s position and velocity. Pass null to drop the source set from code and let the agent choose one automatically again. See “External Control”.
  • public Nav3DAgent[] GetAgentsInRadius(float _Radius, Predicate<Nav3DAgent> _Predicate = null) — agents within _Radius that satisfy the predicate.

More examples are in the imported Demo scenes (see “Getting started”).

New in 3.1.0

With Control mode set to EXTERNAL in Nav3DAgentConfig, the agent finds its path and computes local avoidance as usual but does not apply the result to its transform: your own controller — a flight controller applying forces to a Rigidbody, for example — takes over moving and turning the transform, using the velocity the agent publishes. Every physics tick Nav 3D reads the transform’s position and velocity, every agent computes its velocity, and then OnDesiredVelocityUpdated is raised:

Nav3DAgent m_Agent;
void Awake() => m_Agent = GetComponent<Nav3DAgent>();
void OnEnable() => m_Agent.OnDesiredVelocityUpdated += Steer;
void OnDisable() => m_Agent.OnDesiredVelocityUpdated -= Steer;
void Steer(Vector3 _DesiredVelocity)
{
//your controller computes and applies this tick's forces here
m_Controller.Step(_DesiredVelocity, Time.fixedDeltaTime);
}
  • Apply the velocity in the event handler. The event is raised every tick, including when the agent is at rest, after every agent has computed its velocity and before the physics step, so forces applied there land in that step. A controller that applies the value in its own FixedUpdate instead depends on script order and may act on the previous tick’s value.
  • Where Nav 3D reads the transform’s position and velocity. From the source set with SetStateSource; without one, from a component on the agent’s GameObject that implements INav3DAgentStateSource, else from its Rigidbody, else from the Transform itself. A destroyed source is replaced by the next one in this order. From the Transform alone the velocity is computed from the change in position between ticks: it is zero on the first tick, and a transform moved by a jump (a teleport) reads as one tick of very high speed, so give such an object a Rigidbody or your own source. A source must return the state of the current tick; a reading that throws or is not a number is skipped with an error in the Console, and the agent keeps its last good one.
  • No path, no velocity. DesiredVelocity is zero whenever the agent has no path to follow, for example after Stop or once the command ends. A disabled agent raises no event, so your controller must not keep moving the transform by the last value it received.
  • Avoidance depends on your controller. Local avoidance assumes every agent moves at the velocity it computed, so under External Control it works only as well as your controller follows DesiredVelocity: a slow or weak controller lets agents come closer than their radii. Set the config’s Acceleration to the largest acceleration your controller can actually give the agent, and Max speed at or above its real top speed. An agent under External Control that is not executing a command is still avoided by the other agents, since it may still be moving.
  • Arrival. When the agent reaches its target, DesiredVelocity drops to zero, but a controller that only follows velocity keeps moving for a while and overshoots. Use the Eased motion mode, which brakes along the path, or make your controller brake to a stop at the target itself.
  • Flight. The Flight motion mode works, but its turn model then runs on top of your controller’s own dynamics, and the lags add up. Prefer Constant or Eased, and if you use Flight, set its Max lateral acceleration no higher than the sideways acceleration your controller can actually produce.
  • public Vector3 DesiredVelocity { get; } — the velocity the agent wants this tick, after local avoidance, in units per second.
  • public Vector3 SteeringTarget { get; } — the point the agent steers at this tick: a point on its path, the point it aims at while closing in on a followed target, or the agent’s own position when it is not executing a command.
  • public interface INav3DAgentStateSource { Nav3DAgentState ReadState(); } — Nav3DAgentState holds the world Position of the agent’s transform, and its world Velocity in units per second.

The Nav3DAgent inspector provides debug visualization (enable Gizmos in the Scene view):

  1. Agent radius.

Nav3DAgent: Debug (3)

1. Agent radius visualization.

  1. Normalized agent velocities — yellow: path-following vector; green: local avoidance vector; blue: resulting motion vector.

Nav3DAgent: Debug (4)

2. Normalized agent velocity vectors.

  1. The path the agent follows. It is drawn by Nav3DAgentPathDrawer, so it needs no Gizmos and shows in the Game view too (see “Navigation data visualizers”). New in 3.1.0

Nav3DAgent: Debug (5)

3. The path the agent follows.

  1. Nearby agents considered for local avoidance.

Nav3DAgent: Debug (6)

4. Nearby agents considered for local avoidance.

  1. Nearby obstacle triangles considered for local avoidance.

Nav3DAgent: Debug (7)

5. Nearby obstacle triangles considered for local avoidance.

Nav3DAgent: Debug (8)

6. All debug visualizations enabled at once.

Agent log: if logging is enabled in the config, you can copy the agent log to the clipboard from the inspector.