New extension: State Machine
Description
This extension provides a way to manage Finite State Machines for Scene and Objects with a Behavior.
You can:
- Add as many states as you want
- Connect states together
- Manage transitions easily
- Support start/stop events
- JSON import/export available
(help link is broken until i publish the State Machine Editor, which is ready, but i wait the review here to publish it)
How to use the extension
After you added the extension to your project:
Configuration
If you use it for the scene
- Start the state machine with your first state
- Add as many states as you want to the machine
- Then connect them together
If you use it on an object
- Set a start state in the Configuration, or Add the state then Set the machine to it afterward
- Then add and connect states
You can also use the State Machine Editor to have a GUI and not do all of this by hand: https://gd.games/instant-builds/abbfb1bb-1696-4ac5-a839-281f3cfe537f
Manage states
When your machine is started, here are the good practices for an easy use:
- Check what is the current state
- Test if the state begins
- Do the state actions
- Verify if the state can use a transition to an other state + other required conditions
- Accept the transition
- Test if the state ends
You can then group your events by state.
Checklist
- [X] I've followed all of the best practices.
- [X] I confirm that this extension can be integrated to this GitHub repository, distributed and MIT licensed.
- [X] I am aware that the extension may be updated by anyone, and do not need my explicit consent to do so.
What tier of review do you aim for your extension?
Reviewed
Example file
Extension file
That looks very promising ! I will test it fully later this week but the gd.games example build looks very very promising ! I have a few questions :
- Can you add a condition for a state to trigger ? / How do you trigger a state ?
- Is the state machine calculated efficiently enough to be used 60 times a second even on a mediocre computer ?
This extension is interesting but I'm not sure to understand how it can be used.
For scene switching, I see the "change the scene" actions as transitions already. Scenes usually are changed with a value directly so it can't be a forbidden transitions.
Is it for procedurally generated levels that are split into scenes as a maze?
I usually do FSM inside a scene. I create a dedicated extension with a condition to check the state and one action to do transition. This way I can easily add new states and eventually add some checks if needed. For more complicated FSM, actions can be added to follow more complex states and maybe handle transitions internally.
This last point is very important for FSM on objects. Handling the transitions internally allows a good encapsulation and reusable behaviors. Which is not possible with a general purpose FSM.
Can you explain with practical cases how you see this extension being used?
Thanks for your comments. I'm SORRY bc i expected GitHub to tell me i had comments on this extension :(
@Oxey405 you can brutally set the state yourself, there is an action for that, and it should not be used bc it will break the state flow. But still doable. There are no auto calculation, so yes it run smoothly. You need to ask if a transition between your state and an other is possible (it will only check if the state is in the transition list) then if it meets your condition, you can authorize the transition and it will move to the next state at the start of the next frame.
You are, or are not in a state, and you can only have one state (per machine) at once, so no heavy calculation here.
@D8H there are many practical cases :
-
IA : when you want a NPC to follow a waypoint track for example, it will be easier to think it as stated environement : first, idle state, it gets the waypoint, then follow state, it uses navigation to reach the destination, then come back to idle state. So it can be also used for many other things IA related. I made an example game where the character plays the game by itself. i can publish it. For sim games, or strategy games, having FSM to describe every IA behavior is very common.
-
UI : locking your UI depending on the state it is, is very useful. That's what you see in the example i provided : when you open the export panel, it locks everything else so you can't move or change any state button. I made it using the FSM.
Ping @D8H, it seems you missed the answer from infokub
I have been using this extension for years and it has not been reviewed yet.