Getting Started
Get up and running with State Machine 2 in minutes
This guide will help you create your first state machine in just a few minutes.
Prerequisites
Before you begin, ensure you have:
Unity 6000.3.1f1 or later
Game Creator 2 installed
State Machine 2 installed
Step 1: Create a State Machine Asset
In the Project window, navigate to where you want to create your state machine
Right-click and select Create โ Ninjutsu Games โ State Machine
Name your state machine (e.g., "EnemyAI" or "PlayerController")
Step 2: Open the Graph Editor
Double-click your new State Machine asset to open the Graph Editor.
You'll see a canvas with a Start Node and Exit Node already created. These nodes are automatically added to every new state machine and cannot be deleted.
Step 3: Add an Actions Node
Let's add some behavior:
Right-click on the canvas
Select Create Node โ Actions
Click on the new Actions node to select it
In the Inspector, click Add Action
Choose an action (e.g., Debug โ Log Message)
Configure the action (e.g., type "Hello from State Machine!")
Step 4: Connect the Nodes
Click on the output port (right side) of the Start node
Drag the connection to the input port (left side) of the Actions node
Release to create the connection
Step 5: Add a State Machine Runner
The Runner component executes your state machine on a GameObject:
Create or select a GameObject in your scene
Click Add Component
Search for State Machine Runner
Drag your State Machine asset to the State Machine field
Step 6: Test It!
Press Play in Unity
Check the Console window โ you should see your log message!
๐ Congratulations! You've created your first state machine!
Next Steps
Now that you have the basics, explore these topics:
Add More Behavior
Trigger Nodes โ React to events like player input, collisions, or timers
Branch Nodes โ Create conditional logic paths
Sub-State Machines โ Organize complex logic into reusable modules
Use Variables
Variables โ Store and share data between nodes
Learn the Editor
Graph Editor โ Master the visual editor
Shortcuts โ Speed up your workflow
Build Real Systems
Try building these common use cases:
Enemy AI
Start โ Trigger (On Player Near) โ Actions (Chase)
Door Controller
Trigger (On Interact) โ Branch (Is Locked?) โ Actions
Ability Cooldown
Actions โ Trigger (On Timer) โ Actions (Ready)
Game State Manager
Start โ Sub-State Machine (Menu, Playing, Paused)
Example: Simple Enemy AI
Here's a complete example of a basic enemy AI:
Nodes Setup
Start Node โ Entry point
Trigger Node โ "On Player Enter" (using a trigger collider)
Actions Node โ "Chase Player" (move towards player)
Trigger Node โ "On Player Exit"
Actions Node โ "Return to Patrol"
Connections
This creates a loop where the enemy:
Starts idle
Detects the player โ starts chasing
Loses the player โ returns to idle
Troubleshooting
State Machine Not Running
Ensure the State Machine Runner component is on an active GameObject
Check that the State Machine field has an asset assigned
Verify the Start node has at least one output connection
Actions Not Executing
Check if nodes are enabled (not grayed out)
Verify connections exist between nodes
Use Live Debug in the Graph Editor to see execution flow
Need Help?
Join our Discord Community
Check the full documentation
Email support: [email protected]
Last updated
Was this helpful?