# Action Graphs in Action Sets

> Let an enemy fight with the player's moves: one action in an Action Set plays a combo from an action graph, fed input by input the way a player's presses would.

Markdown version of https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets, a page of the Universal Combat Framework documentation. Link that page when citing it.

> The enemy's AI decides what to do; the player's action graph decides how it plays. One action in an Action Set plays a whole combo from an action graph, pressing its inputs the way a player would.

## Set it up (3 minutes)

1. **Open the combo enemy's Action Set**

   The demo's combo enemy, `BP_UCF_ComboEnemy`, fights with the items the player picks up, drawn through its **Loadout**. Open the Action Set it fights with while it holds the two-handed baton, `ActionSet_UCF_ComboEnemy`, in `Demo/Characters/ComboEnemy`. Its **LightCombo** and **HeavyCombo** cards already play combos from the baton's action graph; the steps below add one of your own beside them.
2. **Add an action and make it a combo**

   Right-click the empty canvas, choose **Add Action** and set its **Action ID** to `ThreeLights`. The card arrives with a **Gameplay Ability** execution method. Open **Execution Method** and pick **Action Graph Combo** instead: one variant appears under **Variants**, with no inputs yet.
3. **List the inputs it presses**

   Under **Variants > Index [ 0 ] > Steps**, press **+** three times and set each **Tag** to `UCF.Input.LightAttack`. **Trigger** already reads **Input Pressed**. Leave **Action Graph** empty: the enemy plays the graph its baton carries.

   In **ActionSet_UCF_ComboEnemy**, under Combo > Variants > Index [0] > Steps, set:

   | Property | Value |
   | --- | --- |
   | Index [ 0 ] Tag | UCF.Input.LightAttack |
   | Index [ 1 ] Tag | UCF.Input.LightAttack |
   | Index [ 2 ] Tag | UCF.Input.LightAttack |

   *Three light attack presses, the same inputs a player holding the baton sends.*
4. **Tell it when to fire**

   On the card's **Scoring > Scorers** list, add a **Distance Scorer**, so the enemy plays the combo in reach rather than from across the room. Raise **Selection Weight** to `5` while you try it, so the AI picks it most of the time.
5. **Save, play, and watch the graph walk**

   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 holding the baton in the Over Shoulder arena; each enemy there picks its weapon as it spawns, and the arena's plate spawns them again. The first lists the enemy's actions above its head, `ThreeLights` in yellow while it runs; the second writes the node its action graph stands in, which steps through the baton's light attacks as the combo plays.

> **Note**
>
> An Action Graph Combo plays moves; it deals no damage of its own. Each swing hits through the melee trace windows on its montage and the trace sockets on the drawn item, exactly as the player's swings do. See [Melee Trace and Damage](https://rigbak.com/docs/universal-combat-framework/melee-trace-and-damage).

---

## How a combo runs

The AI picks the action the way it picks any other: by score, through its gates, after its cooldown, and favored by a chain link. What changes is what happens once it is picked.

- The action hands the variant's inputs to the enemy's action graph, one at a time, the way a player's presses arrive. Each input after the first waits for the running move's action window and chains from there, the way a held combo button does.
- The graph does the rest: it picks the next node from its transitions, plays that node's montage, and opens its trace windows.
- The action ends once the last move has finished and the graph stands back at idle. The action's recovery time starts there, so the enemy pauses after the whole combo rather than after its first swing.

Graph nodes:

- **SwordCombo** (Custom; Combo: AG_MySword, 3 inputs; running): Weight 1; Cooldown none

Graph nodes:

- **ROOT**
- **Light 1** (montage AM_UCF_Sword_Combo)
- **Light 2** (montage AM_UCF_Sword_Combo; running)
- **Light 3** (montage AM_UCF_Sword_Combo)

Connections:

- ROOT to Light 1, through UCF.Input.LightAttack (pressed)
- Light 1 to Light 2, through UCF.Input.LightAttack (pressed)
- Light 2 to Light 3, through UCF.Input.LightAttack (pressed)

*The enemy's Action Set on top, the action graph it plays below. The AI picked SwordCombo, whose one variant feeds three light attack inputs. The graph walks Light 1, Light 2 and Light 3 the way three presses of the player's attack button would, and here it stands in Light 2. While you debug the enemy in Play, both editors light the running card green.*

Take the sword from [First Combo](https://rigbak.com/docs/universal-combat-framework/player/first-combo): three hits on the light attack input. Give an enemy that sword and an action whose one variant presses `UCF.Input.LightAttack` three times, and the enemy plays the same three hits a player does, on the same timing.

> **Note**
>
> An input the graph has no transition for ends the combo early. When moves already played, the action waits for them to finish and ends as a success. When the first input finds nothing, the action fails at once with nothing played. A graph's own **Action Completed** wires play on as usual, and the action ends where the graph comes to rest.

---

## Set up the method

Pick **Action Graph Combo** in an action's **Execution Method**. Its settings sit underneath it.

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

**Category: Execution**

| Property | Value |
| --- | --- |
| Execution Method | Action Graph Combo |

**Category: Execution > Combo**

| Property | Value |
| --- | --- |
| Action Graph | None |
| Variants | 1 Array element |
| Variants > Index [0] > Steps | 3 Array elements |
| Variants > Index [0] > Steps > Index [0] > Tag | UCF.Input.LightAttack |
| Variants > Index [0] > Steps > Index [0] > Trigger | Input Pressed |
| Variants > Index [0] > Steps > Index [0] > Min Hold Seconds | 0.0 |
| Variants > Index [0] > Steps > Index [0] > Max Hold Seconds | 0.0 |
| Variants > Index [0] > Steps > Index [1] > Tag | UCF.Input.LightAttack |
| Variants > Index [0] > Steps > Index [1] > Trigger | Input Pressed |
| Variants > Index [0] > Steps > Index [1] > Min Hold Seconds | 0.0 |
| Variants > Index [0] > Steps > Index [1] > Max Hold Seconds | 0.0 |
| Variants > Index [0] > Steps > Index [2] > Tag | UCF.Input.LightAttack |
| Variants > Index [0] > Steps > Index [2] > Trigger | Input Pressed |
| Variants > Index [0] > Steps > Index [2] > Min Hold Seconds | 0.0 |
| Variants > Index [0] > Steps > Index [2] > Max Hold Seconds | 0.0 |
| Variants > Index [0] > Weight | 1.0 |
| Lock Target | true |
| Combo Timeout | 0.0 (advanced) |

**Category: Execution > Payload**

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

*One variant of three light attack inputs. Action Graph left empty plays the graph the enemy's drawn item carries.*

| Setting | Does |
| --- | --- |
| **Action Graph** | The graph the combo walks, set on the enemy for the action's length. Empty plays the graph the enemy already holds, which its drawn item hands it. |
| **Variants** | The ways to play the combo. Each variant is a list of **Steps** and a **Weight**. One variant is the plain case. |
| **Steps** | The inputs, in order. **Tag** is the input tag a transition in the graph listens for, such as `UCF.Input.LightAttack`; **Trigger** is how it arrives, **Input Pressed** by default. **Min Hold Seconds** and **Max Hold Seconds** hold a press like a held key for a random time in that range, then let go; 0 and 0 press without holding. See [Hold a guard for a while](https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets#hold-a-guard-for-a-while). |
| **Weight** | How often a variant is picked against the others. 0 never picks it. With one variant it does nothing. |
| **Lock Target** | Keeps every attack of the combo aimed at the target its AI is fighting when the combo starts, for the length of the combo. On by default. See [Lock the AI's target for the combo](https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets#lock-the-ais-target-for-the-combo). |
| **Combo Timeout** | Behind **Advanced**. A safety limit in seconds for the whole combo. 0 leaves the graph's own end as the limit. Reaching it ends the action with the **Timed Out** reason. Every action also ends as **Failed** after 30 seconds of running, whatever its timeout says. |

The method's **Payload** category stays empty for a combo: the graph's own nodes carry what each move plays.

---

## Choose the graph it plays

Leave **Action Graph** empty and the combo plays whatever graph the enemy holds. An enemy holds the graph of its drawn item, the same way the player does: the item's **Equippable** fragment names an **Action Graph**, and drawing the item hands it over. Swap the enemy's weapon and its combos follow, with no change to the Action Set.

Set **Action Graph** when one action should play moves the weapon does not carry, such as a boss's grab string. The combo sets that graph on the enemy as it starts and gives the earlier one back when it ends.

| When the action ends | The enemy gets back |
| --- | --- |
| The earlier graph came from its drawn item | Whatever graph its drawn item carries at that moment, so a weapon swapped mid-combo is respected. |
| The earlier graph came from anywhere else | That graph. |
| Something else set a new graph during the combo | Nothing changes: the newer graph stays. |

> **Warning**
>
> Every **Tag** in a variant must match a transition in the graph the combo walks. With **Action Graph** set, saving the Action Set checks this and names the input no transition listens for in the **Asset Check** message log. With it empty, the graph is only known in Play, so a mistyped input shows up as a combo that ends after its last good move.

---

## Play a combo several ways

Add a second variant and the enemy picks one of the two each time it plays the action, by **Weight**. The demo's **LightCombo** works this way: three light attacks with a weight of 2, and a light attack into a heavy one with a weight of 1, so it plays the first two times in three.

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

**Category: Combo**

| Property | Value |
| --- | --- |
| Variants | 2 Array elements |
| Variants > Index [0] > Steps | 3 Array elements |
| Variants > Index [0] > Steps > Index [0] > Tag | UCF.Input.LightAttack (folded until clicked) |
| Variants > Index [0] > Steps > Index [0] > Trigger | Input Pressed (folded until clicked) |
| Variants > Index [0] > Steps > Index [0] > Min Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Steps > Index [0] > Max Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Steps > Index [1] > Tag | UCF.Input.LightAttack (folded until clicked) |
| Variants > Index [0] > Steps > Index [1] > Trigger | Input Pressed (folded until clicked) |
| Variants > Index [0] > Steps > Index [1] > Min Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Steps > Index [1] > Max Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Steps > Index [2] > Tag | UCF.Input.LightAttack (folded until clicked) |
| Variants > Index [0] > Steps > Index [2] > Trigger | Input Pressed (folded until clicked) |
| Variants > Index [0] > Steps > Index [2] > Min Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Steps > Index [2] > Max Hold Seconds | 0.0 (folded until clicked) |
| Variants > Index [0] > Weight | 2.0 |
| Variants > Index [1] > Steps | 2 Array elements |
| Variants > Index [1] > Steps > Index [0] > Tag | UCF.Input.LightAttack |
| Variants > Index [1] > Steps > Index [0] > Trigger | Input Pressed |
| Variants > Index [1] > Steps > Index [0] > Min Hold Seconds | 0.0 |
| Variants > Index [1] > Steps > Index [0] > Max Hold Seconds | 0.0 |
| Variants > Index [1] > Steps > Index [1] > Tag | UCF.Input.HeavyAttack |
| Variants > Index [1] > Steps > Index [1] > Trigger | Input Pressed |
| Variants > Index [1] > Steps > Index [1] > Min Hold Seconds | 0.0 |
| Variants > Index [1] > Steps > Index [1] > Max Hold Seconds | 0.0 |
| Variants > Index [1] > Weight | 1.0 |

*Picked two times in three: three light attacks. One time in three: a light attack, then a heavy one.*

The pick comes from the enemy's own random stream. An enemy whose AI Config ticks **Deterministic** picks the same variants in the same order every run, from the same seed as the rest of its choices. See [Determinism](https://rigbak.com/docs/universal-combat-framework/enemy/determinism).

To pick between whole actions rather than between input lists, such as a combo or a thrown bomb, use an [Action Sequence](https://rigbak.com/docs/universal-combat-framework/sequences-and-random-options) set to pick one step at random.

---

## Hold a guard for a while

A player keeps a guard up by holding the key. A step does the same with **Min Hold Seconds** and **Max Hold Seconds**: the press stays down for a random time in that range, then lets go, and the graph's guard node lowers the guard as it does for a player. The combo moves on once the held move is back at idle.

**Details panel: Guard** (instanced object, in ReactionSet_UCF_DualSwordBoss)

**Category: Combo**

| Property | Value |
| --- | --- |
| Action Graph | AG_UCF_Sword |
| Variants | 1 Array element |
| Variants > Index [0] > Steps | 1 Array element |
| Variants > Index [0] > Steps > Index [0] > Tag | UCF.Input.Guard |
| Variants > Index [0] > Steps > Index [0] > Trigger | Input Pressed |
| Variants > Index [0] > Steps > Index [0] > Min Hold Seconds | 1.5 |
| Variants > Index [0] > Steps > Index [0] > Max Hold Seconds | 3.0 |
| Variants > Index [0] > Weight | 1.0 |
| Lock Target | true |

*Holds the sword's Guard for a random 1.5 to 3 seconds, then lets go, as a player letting go of the key.*

The demo's dual-sword boss guards this way. Its Reaction Set answers a run of hits with a **Guard** reaction: an Action Graph Combo on `AG_UCF_Sword` whose one step presses `UCF.Input.Guard` for 1.5 to 3 seconds. The reaction's rule waits for two blows to land within 5 seconds through a **Hits Taken Gate** and fires four times in five. The boss holds the sword's own guard move, so its block, its stance cost and a guard break work as they do for the player. [Guard after a run of hits](https://rigbak.com/docs/universal-combat-framework/defense#guard-after-a-run-of-hits) covers the gate.

> **Note**
>
> A held press only matters to a move that a held key keeps going, such as a guard. A move that runs to its end on a press plays the same with or without a hold.

---

## Lock the AI's target for the combo

With **Lock Target** ticked, every attack of the combo aims at the target the enemy's AI chose when the combo started, for the length of the combo. Untick it and each attack aims at whatever the AI is focused on as that attack starts.

The enemy aims its moves through **UCF Enemy Attack Steering**, a component **UCF Enemy Character Base** carries. As each move from the graph starts, the component stores the target on the enemy's **UCF Approach** component under its **Approach Target Name**, `Target` to start, and clears it as the move ends.

- An **Approach Window** on the move's montage turns the enemy toward the target and closes the distance, as it does in the enemy's ability attacks. The window's **Approach Target Name** has to match the component's.
- A transition's **Target Distance** and **Target State** conditions read the same target, so a graph can pick a move by how far away the AI's target stands or by what state it is in.
- An enemy on **Enemy Character Base** gets the same by adding a **UCF Enemy Attack Steering** component.

A character without the component, such as one built on the player layer, takes the lock on its **UCF Targeting** component instead, which needs a **Targeting Config**. Leave the config's **Lock Break Distance** at 0, its default, so the lock holds however far the target backs off mid-combo. When the combo ends, the earlier lock comes back; a lock your own Blueprint changed during the combo stays as it is. A character with neither component still plays the combo, and the log warns once.

> **Warning**
>
> UCF Enemy Attack Steering stores no Motion Warping target, so a warp window on a move plays the montage's own motion on an enemy. On an enemy without the component, the graph stores no target for a move: an Approach Window steers only at a target a Blueprint stored, and a transition's **Target Distance** or **Target State** condition finds no target and does not pass, so give such a graph a transition without the condition for the enemy to take.

---

## What the enemy needs

The enemy plays the moves on its own body, so it carries the pieces a player character carries for them. **UCF Enemy Character Base** carries all of them but the action graph component, so `BP_UCF_ComboEnemy`, a child of the demo's enemy built on it, adds that one.

Components panel of **BP_UCF_ComboEnemy**:

- ActionGraph (add)
- Loadout (inherited)
- EquipmentManagerComponent (inherited)
- AnimManagerComponent (inherited)
- Targetable (inherited)
- AttackSteering (inherited)

*The combo enemy's own component, and the ones UCF Enemy Character Base carries for it. Everything else, the AI, its vitals, defense and melee trace, comes from the enemy it is built on.*

| Piece | Why |
| --- | --- |
| **UCF Action Graph** | Runs the graph. Without it the action fails as it starts, and the log names the enemy once. |
| **UCF Enemy Loadout** and **UCF Equipment Manager** | Draw the item whose graph, animation layer and trace sockets the enemy uses: the Loadout names the item, and the Equipment Manager draws it the way the player's character draws. The combo enemy holds the baton; `BP_UCF_ComboEnemy_RandomWeapon` draws the baton, the sword or its fists, picked as it spawns. A disarmed enemy draws the Equipment Manager's **Default Item**, its fists. See [Enemy Weapons](https://rigbak.com/docs/universal-combat-framework/enemy-weapons). |
| **UCF Anim Manager** | Links the drawn item's animation layers to the enemy's Animation Blueprint, and holds the pose for hit stop. |
| **UCF Enemy Attack Steering** | Aims each move at the target the AI fights, holds the target **Lock Target** sets, and gives it to **Target Distance** and **Target State**. |
| Component tags `UCF.Montage` and `UCF.Attachment.Body` on the mesh | Mark the mesh that plays the moves and the one items hang on, as on a player character. UCF Enemy Character Base sets both. |

An enemy built on **Enemy Character Base** adds each of these itself: [Enemy Weapons](https://rigbak.com/docs/universal-combat-framework/enemy-weapons) lists the steps.

The Loadout's **Item Sets** rows hand the AI an Action Set per item, so one enemy fights with a set of baton combos while it holds the baton and a set of sword strings while it holds the sword. The combo enemy names `ActionSet_UCF_ComboEnemy_Sword` and `ActionSet_UCF_ComboEnemy_Unarmed` for the sword and its fists.

Leave **Action Graph** on the method empty and an enemy with no drawn item holds no graph: the action fails as it starts, and the log says to set one or draw an item that carries one. [Character Setup](https://rigbak.com/docs/universal-combat-framework/player/character-setup) covers each player-side component in full; on an enemy they work the same way.

> **Tip: A combo as a reaction**
>
> Action Graph Combo works in a Reaction Set too, so a counter after a parry can be a whole combo from the graph. Behavior Tree Sequence and Action Sequence are the two methods a reaction refuses.

---

## Debug it

| Run | Shows |
| --- | --- |
| `UCF.Debug.EnemyActions 1` | The enemy's actions above its head: green ready, gray with seconds of cooldown left, yellow for the one running. |
| `UCF.Debug.Actions 1` | The node the enemy's action graph stands in, whether its chaining window is open, and any input waiting to chain. |
| `UCF.Debug.Scoring 1` | What each action scored at the last decision, to see why the combo was or was not picked. |

The Action Set editor and the Action Graph editor both follow a debugged enemy in Play: pick the enemy as the debug object and the running card lights green in each.

| Symptom | Cause |
| --- | --- |
| The card's summary line is red and ends in **(incomplete)** | No variant has both a step and a weight above 0. Saving names the variant in the **Asset Check** message log. |
| The action starts and fails at once, nothing plays | The enemy has no **UCF Action Graph** component, or holds no graph and the action names none, or the first input matches no transition. The first two log a warning under `LogUCFBridge`. |
| The combo stops after one or two moves | A later input matches no transition from the node the graph reached. Check the graph's wires for that input. |
| The swings ignore the AI's target | The enemy carries no **UCF Enemy Attack Steering**, the move's montage has no Approach Window, or the window's **Approach Target Name** differs from the component's; see [Lock the AI's target for the combo](https://rigbak.com/docs/universal-combat-framework/action-graphs-in-action-sets#lock-the-ais-target-for-the-combo). |
| The swings miss | The item carries no trace sockets, or the montages no trace windows. The combo plays exactly what the graph would play for a player. |

<details>
<summary>When the combo is cut short (Advanced)</summary>

An action ended early takes its move with it. A reaction, a stun or a death that ends the action also cuts the node the graph is running, so the enemy is free at once for whatever ended it: a blow lands mid-combo, the reaction set's dodge starts, the combo ends with the **Interrupted** reason, and the graph stands back at idle.

The combo leaves the graph alone when something else has taken it over. Queueing another input sequence on the same character replaces the combo's inputs, which ends the action with the **Interrupted** reason; the newer sequence then owns the running move, and a graph the combo set waits until that sequence is done and the graph stands idle before the earlier one comes back.

When two combos overlap on one enemy, the newer one aims the attacks; once it ends, the earlier one aims again, and the AI's focus once neither runs. On a character that takes the lock on its **UCF Targeting** component, overlapping combos share one lock: the lock from before the first of them comes back once the newer one ends. When the target a combo locked stops being a target, by dying for one, the earlier lock comes back; when the earlier target is gone too, the lock clears.

</details>

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

The combo runs on the server, like every execution method: the AI decides there, the graph walks there, and each attack is aimed there. Other machines see the moves through the enemy's animations and its replicated action graph state, and see it turn and close in through its replicated movement.

A graph the action names is set on the server only. Other machines keep showing the graph the enemy holds, so a Blueprint listening for node changes on a client does not follow a graph the combo set.

</details>

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

The method is `UUCFActionGraphExecutionMethod` in the `UCFBridge` module, a subclass of the enemy layer's `UUCFExecutionMethod`. Its variants are `FUCFActionGraphComboVariant` (`Steps`, an array of `FUCFActionInputStep`, and `Weight`).

It drives the character's `UUCFActionGraphComponent` through `CreateInputSequenceDriver` in `EUCFInputSequenceMode::Chain`, the driver behind the **Queue Input Sequence** node, and ends when the driver completes and `IsAtRoot` holds. An interrupting end calls `InterruptActionForExternalAbility`.

`PickVariant(Owner)` returns the variant index a run would pick for that owner, or `INDEX_NONE` when none can be picked. Warnings log under `LogUCFBridge`.

`UUCFEnemyAttackSteeringComponent`, also in `UCFBridge`, is the enemy's action steering provider (`IUCFActionSteeringProvider`): each action graph node's ability pins its target through `PinAttack` and lets it go as it ends. A combo with Lock Target calls `HoldTarget` on it as it starts and `ReleaseTarget` as it ends; the newest hold aims, then the AI controller's focus.

</details>

---

Previous page: [Enemy Weapons](https://rigbak.com/docs/universal-combat-framework/enemy-weapons). Next page: [Sequences and Random Options](https://rigbak.com/docs/universal-combat-framework/sequences-and-random-options)
