Skip to main content

Interface ICommand

The minimal contract for an AI command object: start execution and cancel it.

public interface ICommand

Examples​

// This example shows how to create and execute a move command targeting a world position:
ICommand moveCmd = new AICommand(
actorGameObject,
AICommand.CommandType.GoToLocation,
targetPosition
);
moveCmd.Execute();

// Cancel the active command before completion:
moveCmd.Kill();

Remarks​

AI commands are created externally (by a Timeline playable or game logic), configured with a payload (target position, target transform, etc.), and handed to a supporting invoker. The invoker holds the active command and drives it each frame by calling Execute until the command signals completion internally.

Separating command creation from execution and cancellation enables a few important behaviours:

  • Commands can be queued and replayed without re-running the creation logic.
  • Kill lets external actors (e.g., a study operator abort) cleanly cancel mid-flight without the invoker needing to know which concrete command is running.
  • Timeline scrubbing can create and discard commands without side effects until Execute is actually called.

Methods​

Execute()​

Advances the command by one step; called every frame by the invoker until the command reaches its completion condition.

void Execute()

Remarks​

For commands that are one-shot (e.g., Stop), this should complete immediately. For multi-frame commands (e.g., move to a distant position), this drives the motion each frame and the command clears itself via a completion callback when the goal is reached.

Kill()​

Immediately aborts the command, releasing any resources it holds and signalling the invoker to clear the active command slot.

void Kill()

Remarks​

Called by the invoker when a new conflicting command arrives, or by external code (e.g., a Timeline clip ending) when the command should no longer run regardless of whether it reached its goal.