Basically, I create 3 Resources:
- State
- Condition
- Transition
State is basically just a Resource with a text var that contains the name of the state. But of course you can expand on it, add variables with values for that state, for example.
Condition could be empty, as it's mainly the name of the resource itself that's interesting, but the way I've built it, I added a text var with a name, so I could push a condition to the state machine by name, not just by having a reference to the resource, so then I compare the condition text rather than the condition itself.
Transitions are a resource that combine the 2 above:
- from: State
- condition: Condition
- to: State
The state machine itself has an export Array[State] and an export Array[Transition]. I can create my states, conditions and transitions either directly in the inspector or save them locally then drag them into the arrays. I then send either a Condition or a string to the state machine and it looks through its list to see if it has a matching pair of from and condition, then it executes the transition and emits signals based on that. I use 3 signals for that: StartState, RunState, EndState, so I can have a bit of setup and cleanup, when necessary.
I can show you the project if you like, once I'm back at my home pc.