Task

The engine creates Task objects automatically at the start of each turn to run enemy and NPC behaviours in parallel with the player's action. You can also create tasks manually to schedule any instruction outside the normal sheet.

Task.Status Enum

ValueDescription
UninitializedCreated but not yet started.
RunningCoroutine is actively executing.
FinishedCoroutine ran to completion normally.
InterruptedStopped before completion via Interrupt().

Properties & Events

MemberTypeDescription
statusTask.StatusRead-only. Current state of the task.
OnStartevent System.ActionRaised when Start() is called and execution begins.
OnEndevent System.ActionRaised when the task finishes or is interrupted.

Static Factory Methods

MethodReturnsDescription
GetTask(
  ITaskReceiver receiver,
  ExecutionContext context)
TaskCreates a task from the receiver's own GetTask() definition and the given context.
GetTask(
  ITaskReceiver target,
  Instruction instruction,
  ExecutionContext context)
TaskCreates a task that runs a specific instruction on behalf of a given receiver.

Methods

MethodDescription
Start()Begins task execution immediately. Changes status to Running and raises OnStart.
Stop()Halts the coroutine without changing status to Interrupted.
Interrupt()Halts the coroutine, sets status to Interrupted, and raises OnEnd.
// Run a CustomInstruction as a one-shot task on a MonoBehaviour
var instruction = new CustomInstruction();
instruction.tick = (ctx) => MyRoutine(ctx);

var task = Task.GetTask(receiver, instruction, context);
task.OnEnd += () => Debug.Log("done");
task.Start();

ITaskReceiver

Implemented by objects (typically enemies) that own a task to run each turn. The InstructionRunner queries every registered ITaskReceiver at the start of each turn, retrieves its task, and starts it in parallel with the player's instruction. HUD elements subscribe to the lifecycle events to update indicators in real time.

ℹ️
Registration is automatic Any ExecutionContextElement that also implements ITaskReceiver is discovered and registered with the ExecutionContext during initialization. You do not need to register manually.

Properties

PropertyTypeDescription
currentInstructionInstructionThe instruction currently being executed. Exposed so the HUD can display the enemy's active action.

Events

EventSignatureDescription
OnStartAction<EnemyAction>Raised when task execution begins, passing the first enemy action.
OnActionChangeAction<EnemyAction>Raised each time the active enemy action changes during execution.
OnEndActionRaised when task execution ends.
OnExecuteAction<ExecutionContext>Raised each time an instruction step executes, providing the current context.

Methods

MethodReturnsDescription
GetTask()TaskReturns the Task this receiver should run during the current turn. Called by InstructionRunner at the start of every turn.
Execute()voidTriggers execution of the task. Called by the runner after GetTask().