Your First State Machine
Build a three-state loop that waits in Idle, enters Patrol, writes a Console message in Log, and returns to Idle. The graph provides a visible active-state sequence and one controlled value to change.
Before you begin
- Complete Getting Started.
- Confirm the project uses Unity 2022.3.11 or newer and Entities 1.3.8.
- Use a saved scene outside the imported sample folder.
Create the graph owner
- Create an empty GameObject and name it
FirstStateMachine. - Open Tools > Opsive > State Designer > Editor.
- Keep
FirstStateMachineselected. - Right-click empty graph space and select Add State Machine, or use the operations-toolbar add button.
The editor should show the selected GameObject, its state machine, the Element Inspector, and the Shared Variables panel.

Add the states
- Press Space and add an Idle state.
- Add an Action State, rename it
Patrol, and add a Wait Action with a duration of1second. - Add another Action State, rename it
Log, and add a Log Action with the textState machine cycle complete. - Connect Start to Idle.
- Connect Idle to Patrol, Patrol to Log, and Log back to Idle.
The resulting graph forms a left-to-right flow with a return transition below it.

Configure the transitions
- Select the Idle-to-Patrol transition.
- Replace State Finished with Timer and set its duration to
1second. - Keep Patrol-to-Log and Log-to-Idle on State Finished.
- Open the Error Window and resolve every missing state, transition, or required field.

Idle has no Action that finishes, so its Timer transition provides the exit. Patrol finishes after Wait. Log writes the message and finishes immediately, allowing its default State Finished transition to return to Idle.
Verify in Play Mode
- Clear the Unity Console and enter Play Mode.
- Watch Idle become active for one second.
- Watch Patrol remain active while its Wait Action runs.
- Confirm that Log activates, the Console prints
State machine cycle complete, and the graph returns to Idle. - Observe at least two complete cycles.

Pause Play Mode while Patrol is active if Log finishes too quickly to see. The active-state highlight and repeated Console message together prove that state entry, Action completion, and transition evaluation are all working.
Make one controlled change
Change the Idle Timer from one second to three seconds. The state order should stay the same while Idle remains active longer. If another part of the cycle changes, inspect the transition you edited and undo unrelated graph changes.
Troubleshooting
| Symptom | Check | Fix |
|---|---|---|
| No state becomes active. | Selected owner, enabled State Machine component, Start connection, and Console errors. | Select or enable the correct owner, connect Start to Idle, and resolve compile errors. |
| The graph remains in Idle. | Idle-to-Patrol Timer Condition and Evaluation Mode. | Assign Timer, set a positive duration, and use Continuous evaluation. |
| Patrol never finishes. | Wait duration and Action execution. | Use a finite positive Wait and confirm the Action is enabled. |
| Log never activates. | Patrol-to-Log connection and State Finished Condition. | Restore the transition and its default Condition. |
| The graph loops too quickly. | Timer and Wait values. | Use visible one-second values before tuning the production graph. |
Use Debugging when the first invalid state or transition is not clear.
Continue learning
- Use Transition Evaluation and Priority before adding competing transitions.
- Adapt a complete Common Graph.
- Use Shared Variables when Actions and Conditions need the same data.
- Use Subgraphs when a reusable region should become its own asset.