A lightweight, fast Finite State Machine implemented as a C++ GDExtension.
Click the AssetLib
button at the top of the Godot editor and search for EzFSM
. When prompted where to install it, you can select only the folder named "addons". If you wish to modify or recompile the addon, then you'll need to include the "godot-cpp" and "src" folders along with the "SConstruct" file from this repository.
Head over to the EzFSM page on the asset library website and click the download button. Unzip the download into a location of your choosing. To put the addon in your project, just copy the "addons" folder into the project directory.
You can download the full repository for EzFSM here. You can clone this repository by doing git clone https://github.com/iiMidknightii/EzFSM.git
in the directory of your choosing. If you want to compile your own binaries this is the best option. To put the addon in your project, just copy the "addons" folder into the project directory.
First, to create a state machine, simply add a StateMachine
node to your scene.
Tip
When you first add a state machine, there will be warnings that tell you that you need to add states and set the default. They will go away once we start editing the state machine.
If you have EzFSM enabled in the plugins screen, clicking the state machine node will open a blank graph editor. You can add the first state by right clicking and selecting Add State
, or pressing the leftmost button in the toolbar.
This adds a new state to the machine with the name NewState
.
You can add a custom script to that state with the Add Script
button.
Important
If you don't add a script to a state, it will not do any processing.
If you included the script_templates folder in your project, you can use the default State
template to populate the default virtual method interfaces.
Once you have two or more states added to the machine, you can connect states you wish to allow transitions between by dragging the white dot on the bottom right of one state to the white dot on the bottom left of another.
Once connected, the state that can transition to the other state will have a transition showing the name of the state it transitions to, as well as the ability to add a custom script to define the logic of when that transition will occur. Click the name of the transition to edit its resource object. If more than one transition is added, they are evaluated in descending order starting at the top. You can change that order with the arrow buttons that will appear to the left of the transitions' names. Disconnect states by dragging the purple end of the connection away from the right port of the transition.
Important
The transition will have a yellow icon if it has no script attached. Without a script, the transition will always return false
and therfore never activate. Attach a script and return true
in at least one of the virtual methods when you want to continue to the connected State.
Tip
You can set a state as the default by clicking the button, disable a state for activation/processing with the
button, allow a state to transition to itself with the
button, and change the color of a state's title bar with the
and the color picker that appears.
- v1.0.2 - Ensured
auto_start
functionality takes place after_ready
is called on the machine and itscontext
. Also added the ability to run the state machine in the editor (with@tool
scripts attached), and ensured propery resource ownership and cleanup.
Feel free to leave any feedback, suggestions, bug reports, and contributions to the repository at https://github.com/iiMidknightii/EzFSM.