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
| Value | Description |
Uninitialized | Created but not yet started. |
Running | Coroutine is actively executing. |
Finished | Coroutine ran to completion normally. |
Interrupted | Stopped before completion via Interrupt(). |
Properties & Events
| Member | Type | Description |
status | Task.Status | Read-only. Current state of the task. |
OnStart | event System.Action | Raised when Start() is called and execution begins. |
OnEnd | event System.Action | Raised when the task finishes or is interrupted. |
Static Factory Methods
| Method | Returns | Description |
GetTask( ITaskReceiver receiver, ExecutionContext context) | Task | Creates a task from the receiver's own GetTask() definition and the given context. |
GetTask( ITaskReceiver target, Instruction instruction, ExecutionContext context) | Task | Creates a task that runs a specific instruction on behalf of a given receiver. |
Methods
| Method | Description |
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
| Property | Type | Description |
currentInstruction | Instruction | The instruction currently being executed. Exposed so the HUD can display the enemy's active action. |
Events
| Event | Signature | Description |
OnStart | Action<EnemyAction> | Raised when task execution begins, passing the first enemy action. |
OnActionChange | Action<EnemyAction> | Raised each time the active enemy action changes during execution. |
OnEnd | Action | Raised when task execution ends. |
OnExecute | Action<ExecutionContext> | Raised each time an instruction step executes, providing the current context. |
Methods
| Method | Returns | Description |
GetTask() | Task | Returns the Task this receiver should run during the current turn. Called by InstructionRunner at the start of every turn. |
Execute() | void | Triggers execution of the task. Called by the runner after GetTask(). |