# Sequences and Random Options

> Run several actions as one move: an ability, a Behavior Tree and an action graph combo in order, or one of them picked at random, repeatable from a seed.

Markdown version of https://rigbak.com/docs/universal-combat-framework/sequences-and-random-options, a page of the Universal Combat Framework documentation. Link that page when citing it.

> One action can run other actions of its set: an ability attack, then a combo from the action graph, then a Behavior Tree that backs off, in order. Or one of them, picked at random by weight.

## Set it up (3 minutes)

1. **Add an action to the combo enemy's set**

   Open `ActionSet_UCF_ComboEnemy` in `Demo/Characters/ComboEnemy`. Right-click the empty canvas, choose **Add Action** and set its **Action ID** to `SlashThenCombo`.
2. **Make it a sequence of two actions**

   Open **Execution Method** and pick **Action Sequence**. Press **+** twice on **Steps** and set the two **Action ID** fields to `SingleAttack` and `LightCombo`, two actions the set already has.

   **Details panel: SlashThenCombo** (instanced object, in ActionSet_UCF_ComboEnemy)

   **Category: Execution**

   | Property | Value |
   | --- | --- |
   | Execution Method | Action Sequence |

   **Category: Execution > Sequence**

   | Property | Value |
   | --- | --- |
   | Steps | 2 Array elements |
   | Steps > Index [0] > Action Id | SingleAttack |
   | Steps > Index [0] > Weight | 1.0 |
   | Steps > Index [1] > Action Id | LightCombo |
   | Steps > Index [1] > Weight | 1.0 |
   | Pick One at Random | false |
   | Sequence Timeout | 0.0 (advanced) |

   **Category: Execution > Payload**

   | Property | Value |
   | --- | --- |
   | Payload | None |

   *Steps run top to bottom. Weight counts only once Pick One at Random is ticked.*
3. **Tell it when to fire**

   On the card's **Scoring > Scorers** list, add a **Distance Scorer**, and raise **Selection Weight** to `5` while you try it.
4. **Save, play, and watch both steps**

   Save the Action Set, open `LVL_UCF_Demo` and press Play. Run `UCF.Debug.EnemyActions 1` and `UCF.Debug.Actions 1`, then walk up to a combo enemy. `SlashThenCombo` turns yellow and stays yellow while the enemy plays its single attack and then the light combo, the action graph's node stepping through the combo above its head.

The demo's set carries both kinds already: **AbilityComboTree** runs an ability attack, a graph combo and a Behavior Tree move in that order, and **EitherCombo** picks one of its steps at random.

---

## Run several actions as one

**Action Sequence** runs other actions of the same Action Set, named by their **Action ID**. Each step runs through its own action's execution method, with that action's own settings and payload, so any mix works: a **Gameplay Ability** attack, a **Behavior Tree Sequence** that walks in first, an **Action Graph Combo** from the action graph. The demo's **AbilityComboTree** shows the order: the ability plays first, the combo walks the graph next, and the Behavior Tree runs last.

One run of SlashThenCombo. Top to bottom.

1. **The AI picks the sequence** (SlashThenCombo): Scored, gated and picked like any other action, and its own cooldown is charged as it starts.
2. **Step 1 runs SingleAttack** (SingleAttack's own execution method): Whatever SingleAttack runs, an ability or a Behavior Tree, runs here with SingleAttack's own settings and payload. The step ends when that method ends.
3. **Step 2 runs LightCombo** (Action Graph Combo): The combo walks the enemy's action graph. The step ends once the graph is back at idle.
4. **The sequence ends** (Completed): Its recovery time starts. SingleAttack and LightCombo keep their own cooldowns untouched, so the AI can still pick either one on its own.

A step that fails or is cut short ends the whole sequence with that step's reason, and the steps after it never run.

| Setting | Does |
| --- | --- |
| **Steps** | The actions to run, by **Action ID**, top to bottom. Each one names another action in the same set. |
| **Weight** | On each step. How often it is picked against the others; read only with **Pick One at Random** ticked. 0 never picks it. |
| **Pick One at Random** | Runs one step picked by weight instead of every step in order. Off by default. |
| **Sequence Timeout** | Behind **Advanced**. 0 lets each step keep its own action's timeout. Above 0, this limit replaces theirs and restarts for each step that restarts its own, as a **Behavior Tree Sequence** does per tree. Reaching it ends the action with the **Timed Out** reason. The whole sequence also ends as **Failed** after 30 seconds of running, whatever its timeout says. |

On the canvas, a sequence card lists its steps on its summary line.

Graph nodes:

- **SlashThenCombo** (Custom; Sequence: SingleAttack, LightCombo): Weight 1; Cooldown none
- **AnyCombo** (Custom; One of: LightCombo, HeavyCombo): Weight 1; Cooldown none

*An Action Sequence card lists its steps on its summary line: Sequence for steps run in order, One of for a sequence that picks one step at random. A sequence draws no wire to the actions it names; a wire on this canvas is a chain link.*

---

## What counts once, and what each step keeps

The sequence is one action to the AI. Its own scorers and gates decide when it is picked, its own cooldown is charged as it starts, and its own recovery time follows it. The actions it names are only borrowed:

- **A step runs on the sequence's say-so.** Its own scorers, gates and cooldown are not checked, and running it as a step charges none of its cooldown. The AI can still pick that action on its own between sequences.
- **A step brings its own payload and ability.** An ability reading its action's payload reads the step's payload, and a Behavior Tree step's **Activate Action Ability** node starts the step's own **Ability to Grant**.
- **Keep each step's action Enabled.** An unticked **Enabled** also stops that action's ability being granted, which leaves the step nothing to start. To keep the AI from picking a step on its own, set that action's **Selection** to **Manual Only**: a sequence still runs it.

A step that fails or is cut short ends the whole sequence with that step's reason, and the steps after it never run. An action ended early, by a reaction, a stun or a death, ends its running step with it.

> **Warning**
>
> A step cannot name another **Action Sequence**, so a sequence never runs itself: list that sequence's steps instead. Saving the Action Set refuses it in the **Asset Check** message log, along with an empty **Action ID** and a name the set does not have. An Action Sequence also cannot run as a reaction, since its steps come from the Action Set.

---

## Pick one at random

Tick **Pick One at Random** and each run plays one step, drawn by **Weight**. The demo's **EitherCombo** works this way. In this one of your own, `AnyCombo`, `LightCombo` plays two times in three and `HeavyCombo` one time in three:

**Details panel: AnyCombo** (instanced object, in ActionSet_UCF_ComboEnemy)

**Category: Sequence**

| Property | Value |
| --- | --- |
| Steps | 2 Array elements |
| Steps > Index [0] > Action Id | LightCombo |
| Steps > Index [0] > Weight | 2.0 |
| Steps > Index [1] > Action Id | HeavyCombo |
| Steps > Index [1] > Weight | 1.0 |
| Pick One at Random | true |

*Each run plays one of the two combos: LightCombo two times in three, HeavyCombo one time in three.*

The two kinds of randomness answer different questions:

| Use | When the choice is between |
| --- | --- |
| An **Action Graph Combo** with several **Variants** | Input lists played on one action graph: three light attacks, or a light into a heavy. See [Action Graphs in Action Sets](https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets#play-a-combo-several-ways). |
| An **Action Sequence** with **Pick One at Random** | Whole actions of any kind: a combo, an ability, a Behavior Tree. |

---

## Three ways to combine actions

| Way | What the AI does | Set it on |
| --- | --- | --- |
| A chain link | Favors the follow-up for a moment after an action ends. The AI may still pick something else, and the follow-up runs as its own action, with its own cooldown. | The first action's **Chain Links**, or a wire between two cards. See [Action Set Editor](https://rigbak.com/docs/universal-combat-framework/enemy/action-set-editor). |
| An **Action Sequence** in order | Commits to every step, one after another, as one action. | A new action naming the steps. |
| An **Action Sequence** that picks one | Commits to one step, drawn by weight. | The same, with **Pick One at Random**. |

A chain link works across every execution method, so an ability attack can lead into a graph combo and on into a Behavior Tree move with nothing but wires on the canvas. Reach for a sequence when the moves must always come together.

---

## Repeat it exactly

Variant picks and random steps come from the enemy's own random stream. Tick **Deterministic** on the enemy's AI Config and the enemy picks the same variants and the same steps in the same order every run, built from **Default Seed** like the rest of its choices. Two enemies sharing one config still pick differently from each other, since each mixes the seed with its own name.

Give a combo enemy seed 7 and every fight draws its combo variants in the same order as the fight before. See [Determinism](https://rigbak.com/docs/universal-combat-framework/enemy/determinism) for the seed, the start barrier and how to prove a fight repeats.

---

## Debug it

| Run | Shows |
| --- | --- |
| `UCF.Debug.EnemyActions 1` | The sequence in yellow for its whole run, above the enemy's head. |
| `UCF.Debug.Actions 1` | The node the enemy's action graph stands in while a combo step plays. |
| `UCF.Debug.Scoring 1` | What the sequence scored at the last decision. |

| Symptom | Cause |
| --- | --- |
| The card's summary line is red and ends in **(incomplete)** | No steps, a step with no **Action ID**, or **Pick One at Random** with every weight at 0. |
| The sequence starts and fails at once | A step names an action the enemy's current Action Set does not have, or another Action Sequence. The log warns under `LogUCFBridge` with the step's name. |
| A step's ability never starts | That action is unticked **Enabled**, so its ability was never granted. |
| The sequence ends early | A step failed or was cut short; the sequence ends with that step's reason. |

<details>
<summary>Where it runs (Multiplayer)</summary>

A sequence runs on the server, like every execution method, and each step with it. Other machines see each step the way they see that action on its own: an ability's montage, a combo's moves through the enemy's animations.

</details>

<details>
<summary>C++</summary>

The method is `UUCFActionSequenceExecutionMethod` in the `UCFBridge` module; a step is `FUCFActionSequenceStep` (`ActionId`, `Weight`). `PickSteps(Owner)` returns the step indices a run plays, empty when nothing can run.

Each step duplicates the named action's execution method, found through `UActionEvaluationComponent::FindActionSpec`, and drives the copy through its own begin, tick and abort. The next step starts on the sequence's next tick, never inside the callback that ended the last one. `GetPayload`, `GetAbilityToGrant` and `GetAbilityActivationPlan` answer with the running step's, and `CanRunAsReaction` returns false.

</details>

Previous page: [Action Graphs in Action Sets](https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets). Next page: [Seam Patterns](https://rigbak.com/docs/universal-combat-framework/seam-patterns)
