Scripting
CustomInstruction
An Instruction subclass that lets you define execution behaviour entirely through delegates, without creating a new class. Useful for one-off or procedurally generated instructions at runtime.
CustomInstruction
Extends Instruction directly. Instead of overriding Tick() in a subclass, you assign a coroutine delegate to tick. The runner treats it identically to any other instruction.
Properties
| Property | Type | Description |
|---|---|---|
displayName | string | Label shown by the instruction pointer HUD. Defaults to an empty string — set it when you want the UI to identify this instruction. |
Delegates
| Member | Type | Description |
|---|---|---|
execute | event Action | Invoked by Execute() before Tick() runs. Subscribe to perform any non-coroutine setup or side-effects when the instruction starts. |
tick | Func<ExecutionContext, | The coroutine that drives the instruction's behaviour. Receives the current ExecutionContext and must yield at least once. If null, the instruction yields once and returns immediately. |
Methods
| Method | Description |
|---|---|
Execute() | Invokes the execute event. Called by the runner before Tick(). |
Tick(ExecutionContext context)override |
Delegates to the tick function. If tick is null, yields once and returns. |
Usage
Create a CustomInstruction, assign its coroutine to tick, and optionally subscribe to execute for any synchronous setup that should run before the coroutine starts.
IEnumerator HealRoutine(ExecutionContext context) { context.inventory.TryUseItem(healthPotion); context.player.UseItem(healthPotion); yield return new WaitForSeconds(0.3f); } var instruction = new CustomInstruction(); instruction.displayName = "Heal"; instruction.tick = (ctx) => HealRoutine(ctx); instruction.execute += () => Debug.Log("Heal started");
CustomInstruction vs subclass
Use
CustomInstruction for transient, runtime-generated behaviour — scripted events, tutorial prompts, or instructions assembled from data. For reusable player actions that appear in the palette, extend PlayerInstruction instead.