Use this graph when one parent flow should run interchangeable melee, ranged, or other attack behavior without duplicating the surrounding states.

In the editor

  1. Author and test each attack as its own Subgraph. Give the variants the same external inputs where possible, such as Target and Attack Speed.
  2. In the parent graph, add a Subgraph Reference Selector where the attack mode belongs.
  3. Add the Subgraphs to its list in a stable order, such as Melee Attack at index 0 and Pistol Attack at index 1.
  4. Create an integer Shared Variable named Attack Subgraph Index and assign it to Subgraph Index.
  5. Add Shared Variable Overrides that map the selected Subgraph’s inputs to the parent graph’s Target and configuration values.
  6. Keep Reevaluate On Index Change enabled only when changing the variable should rebuild the references and restart the graph automatically.

A Subgraph Reference maps a source Shared Variable to a value supplied by its parent graph.

After importing the samples, the Subgraph Replacement scene and its MeleeAttack and PistolAttack assets provide a concrete version of this pattern.

How it runs

Before the graph starts, Subgraph Reference Selector reads Attack Subgraph Index and injects the one Subgraph at that list position. The parent graph then runs the selected states and transitions as part of its own flow.

When Reevaluate On Index Change is enabled, changing the index queues reference reevaluation at the end of the frame. State Designer rebuilds the injected content and restarts the graph. Make that change at a safe mode boundary when restarting in-progress behavior would be visible.

Key choices

  • Keep the Subgraph list order stable because the index selects by position.
  • Map variables by purpose. Both attack variants can receive the parent’s Target even when their internal Actions differ.
  • Use an ordinary Subgraph Reference when the referenced behavior never changes.
  • Split only cohesive behavior into a Subgraph. A tiny one-state asset can be harder to follow than leaving that state in the parent.

Verify in Play Mode

Start once with index 0 and confirm the melee states are injected and run. Change to index 1 at a safe point and confirm the graph restarts with the pistol states. Verify that both variants receive the same parent Target through their overrides.