A Godot plugin that manages state machines & state transitions.
It features:
- A StateMachine based on nodes
- Nested StateMachines
- Pushdown Automata
- Automatic animation triggering directly AnimatedSprite
- A powerful GraphEditor to handle state transitions
- State change based on signals and as many conditions you want
This addon is under MIT license, which means it is free to use/copy/modify etc. If you want to help its creator financially, you can tip him here
💾 Install 💾
You can either:
- Browse StateGraph in the AssetLib tab inside Godot, and install it from there, using Godot's plugin install interface.
- Clone this repo in a folder
addons/StateGraph
a the root of your project; then activate the plugin in ProjectSettings -> Plugins
📃 Documentation 📃
You can find detailed, by-class Documentation and a tutorial on how to use the GraphEditor here.
🕵️ Overview 🕵️
Basic use
StateGraph is an implementation of the State -also known as Finite State Machine- design pattern.
It uses two types of nodes: a StateMachine node that handles its State children, like in this example below.
You can inherit the State class to associate it with your logic or use basic State nodes if you are doing a StateMachine dedicated to animation for example.
If you inherit the State class, be aware that your scripts must have the tool
keyword for it to work with the GraphEditor.
You can find more information about how to use the State class and every other in the Documentation.
Graph Editor
The GraphEditor is a tool that runs inside Godot's editor and allows you to manage & edit the Connections between states as well as standalone triggers.
Connections can be triggered either by signals or in the _physics_process()
of the StateMachine.
Additionally, it can take any conditions that must all return true for the change of State to operate.
The graph also implements standalone triggers that work precisely as Connections but does not need to be in a particular state to trigger.
It is designed to be very flexible and to keep the graph as readable as possible by minimizing the number of Connections you need to make between two states. If it is correctly used, it will prevent you from writing any boilerplate state transition code. (You can still do it by code tho)