Skip to main content

Class MoveCommandInvoker

An invoker that manages a single active movement command for an actor, dispatching per-frame execution and providing pause/resume/kill control over it.

public class MoveCommandInvoker : MonoBehaviour, IMoveCommandInvoker, IHasUnityContext

Inheritance​

Implements​

Examples​

The following shows the two primary call-site patterns found in the project.

Pattern 1 — BT task calls FollowPath once per tick (AIBrainComponent.MoveToDestination → PathFollowBehavior.FollowPath). The BT task calls Transform) every frame while the task is active; the idempotency guard means the underlying command is not recreated unless the destination actually changes.

// Inside a BT [Task] method — called every frame while the task is running:
IMoveCommandInvoker invoker = GetComponent();
invoker.MoveToLocation(waypointTransform); // safe to call every frame; no thrash
ThisTask.Succeed();

Pattern 2 — Traffic process uses Pause / Resume around a stop event (AntiCollisionOtherCarsProcess). The process pauses the invoker when a leading vehicle enters the forward arc, then resumes it once the arc is clear. The command destination is retained across the pause so the vehicle continues toward the same goal without needing a new Transform) call.

// Enter stop zone — halt without discarding the current destination:
invoker.PauseCommand();

// Exit stop zone — continue toward the retained destination:
invoker.ResumeCommand();

// Permanent cancel (e.g., actor despawn or path invalidated):
invoker.KillCommand(); // destination is discarded; must call MoveToLocation to restart

Remarks​

Only one move command is active at a time. When a new destination arrives, the previous command is killed before the new one is started. This prevents two conflicting commands from fighting over the actor's velocity simultaneously.

An idempotency guard in each MoveToLocation overload checks whether the incoming destination matches the currently running command. If it does, the existing command is left running rather than being restarted, preventing thrashing when a caller issues the same destination every frame (which Timeline clips tend to do).

Methods​

KillCommand()​

Immediately stops and discards the active command; the actor will not resume movement until a new command is issued.

public void KillCommand()

Remarks​

Use to permanently cancel a move (e.g., the actor's path was invalidated, or the actor is being despawned). For a temporary halt that may be resumed, use PauseCommand instead.

MoveAlongPath(CinemachinePathBase)​

Issues a command to follow a Cinemachine spline path from start to end using the default arrival radius at the path's final position.

public void MoveAlongPath(CinemachinePathBase path)

Parameters​

NameTypeDescription
pathCinemachinePathBaseThe Cinemachine path to follow.

MoveAlongPath(CinemachinePathBase, float)​

Issues a command to follow a Cinemachine spline path with a custom XZ arrival radius at the path's final position.

public void MoveAlongPath(CinemachinePathBase path, float acceptableRadius)

Parameters​

NameTypeDescription
pathCinemachinePathBaseThe Cinemachine path to follow.
acceptableRadiusfloatHorizontal distance from the path end at which the actor is considered to have arrived.

Remarks​

Applies the default look-ahead settings. Callers that own path-specific tuning, such as PathFollowBehavior, should use the overload that supplies those values.

MoveAlongPath(CinemachinePathBase, float, float, float, float, float)​

Issues a command to follow a Cinemachine spline path using caller-supplied steering look-ahead settings, which belong to the path follower rather than the invoker.

public void MoveAlongPath(CinemachinePathBase path, float acceptableRadius, float minLookAheadDistance, float maxLookAheadDistance, float lookAheadTime, float curveSensitivity)

Parameters​

NameTypeDescription
pathCinemachinePathBaseThe Cinemachine path to follow.
acceptableRadiusfloatHorizontal distance from the path end at which the actor is considered to have arrived.
minLookAheadDistancefloatMinimum steering preview distance in meters.
maxLookAheadDistancefloatMaximum steering preview distance in meters.
lookAheadTimefloatPreview time in seconds, multiplied by horizontal speed. Zero yields a fixed minimum preview.
curveSensitivityfloatHow strongly upcoming heading changes shorten the preview; zero disables curve adjustment.

Remarks​

The idempotency guard matches on path and arrival radius only, so a command already running for the same path is reused and the look-ahead arguments are not re-read. Changing those values at runtime therefore takes effect on the next new path command, which keeps per-frame callers from rebuilding the command continuously.

MoveToLocation(Vector3)​

Issues a move command to a fixed world-space position using the default arrival radius.

public void MoveToLocation(Vector3 location)

Parameters​

NameTypeDescription
locationVector3The target world-space position.

MoveToLocation(Vector3, float)​

Issues a move command to a fixed world-space position with a custom XZ arrival radius.

public void MoveToLocation(Vector3 location, float acceptableRadius)

Parameters​

NameTypeDescription
locationVector3The target world-space position.
acceptableRadiusfloatHorizontal distance at which the actor is considered to have arrived.

MoveToLocation(Transform)​

Issues a move command that tracks a moving transform, re-evaluating the goal each tick so the actor follows if the target moves.

public void MoveToLocation(Transform transform)

Parameters​

NameTypeDescription
transformTransformThe transform to follow.

MoveToLocation(Transform, float)​

Issues a move command that tracks a moving transform with a custom XZ arrival radius.

public void MoveToLocation(Transform targetTransform, float acceptableRadius)

Parameters​

NameTypeDescription
targetTransformTransform
acceptableRadiusfloatHorizontal distance at which the actor is considered to have arrived.

PauseCommand()​

Suspends execution of the active command without discarding it; movement stops immediately but the destination is retained.

public void PauseCommand()

Remarks​

The BT uses this to stop the actor at a stop line or intersection while waiting for a signal, without losing the current destination. Call ResumeCommand to continue toward the same destination when conditions clear.

ResumeCommand()​

Resumes a previously paused command, continuing movement toward the retained destination.

public void ResumeCommand()
  • Examples
  • Remarks
  • Methods
    • KillCommand()
    • MoveAlongPath(CinemachinePathBase)
    • MoveAlongPath(CinemachinePathBase, float)
    • MoveAlongPath(CinemachinePathBase, float, float, float, float, float)
    • MoveToLocation(Vector3)
    • MoveToLocation(Vector3, float)
    • MoveToLocation(Transform)
    • MoveToLocation(Transform, float)
    • PauseCommand()
    • ResumeCommand()