Switch on a state
Build a switch node on the canvas with one case per enemy state, then wire each state's calls to its own case.
On this page
When one state decides what an object does, a switch gives each state its own output and its own row of calls. On the canvas it is a yellow node with SWITCH in its header, a Selection pin that takes the state, and one white output per case. In the Platformer sample, an enemy can be patrolling, stunned, or defeated, and each case answers one question: what should this enemy do now?
This page builds that shape from an empty canvas. It uses the sample’s EnemyStateMachine class so every name on the nodes is real. In your own project, build the same shape in any class that holds a state, once its folder is indexed.
In the sample
Section titled “In the sample”Changing an enemy’s state touches several of its parts at once: patrol movement, the body collider, and the defeated look. Each state turns those parts on or off in its own way, and the switch keeps each state’s calls together where you can see them.
When this applies
Section titled “When this applies”- An enemy that patrols, chases, or is stunned needs different behavior in each state.
- A pickup does something different for each item type: coin, heart, or key.
- A menu, a door, or a boss fight moves through named phases, and each phase sets things up its own way.
Switch on the enemy state
Create ShowState
Open Tools > Round Trip > Graph view, press Cmd/Ctrl+O and choose EnemyStateMachine. Press the + on the Methods section of the left rail, type
ShowStatein the name box and press Enter. The canvas shows a magenta entry node titled ShowState with an Exec pin.
5 stepsFull size ↗Place the switch
Right-click blank canvas and pick switch under flow control. A yellow node with SWITCH in its header appears, with Exec and Selection on its left and Add pin at its foot. Wire the entry node’s Exec into the switch’s Exec.
5 stepsFull size ↗Feed it the state
Give it the state. Right-click, type
CurrentState, and press get on its row. Drag the CurrentState pill onto the switch’s Selection pin.
5 stepsFull size ↗Add the cases
Press Add pin on the switch node three times.
Name the cases
Name the cases. Right-click the switch node and choose Edit switch cases. The Switch cases panel lists the cases by number, each with a Matches box and a When guard box. Type
EnemyState.Patrollinginto the first Matches box,EnemyState.Stunnedinto the second andEnemyState.Defeatedinto the third. Click outside the panel to close it. The node’s outputs now carry the state names.
8 stepsFull size ↗Patrolling
Patrolling. Right-click blank canvas, type
SetPatroland click the SetPatrolEnabled row. A bright teal node appears, its Target showing self, with an isEnabled checkbox. Tick isEnabled and wire the first case output into the node’s Exec. Place a SetBodyColliderEnabled node the same way and tick its isEnabled. Then wire the first node’s Exec output into it.
13 stepsFull size ↗Stunned
Stunned. Place another SetPatrolEnabled node, leave isEnabled unticked, and wire the second case output into it.
8 stepsFull size ↗Defeated
Defeated. Place SetPatrolEnabled and SetBodyColliderEnabled nodes with isEnabled unticked, then ApplyDefeatedVisual, and chain all three from the third case output with white wires.
19 stepsFull size ↗Compile
Press Compile in the toolbar.
Each new case ends on its own. When a case’s last node runs, the switch is done, and the next case’s nodes never run after it.
What it writes
Section titled “What it writes”If you also work in C#, this is the sample’s ApplyState, drawn as the diagram beside the code. Your ShowState writes the same three cases.
A new case starts with its own break, so a case placed on the canvas never falls through into the next one. A case whose matches box is still empty is refused by name at Compile until you say what it matches.
When it goes wrong
Section titled “When it goes wrong”When it goes wrong
| Symptom | Check | Fix |
|---|---|---|
| Compile refuses with a case that has no name. | Open Edit switch cases and look for an empty matches box. | Type the state into it, or press Remove on that case. |
| A new state has no visible behavior. | Compare the state names with the switch node's outputs. | Press add pin, name the new case in Edit switch cases, and wire its calls. |
| Defeated enemies still collide. | Follow the Defeated output to its SetBodyColliderEnabled node. | Untick that node's isEnabled box, then Compile. |
- Switch: add and read switch cases.
- Enums and data classes: understand the value that selects a case.
- Method calls: inspect the component-setting calls inside each state.


