What is a State Machine?
A state machine refers to a mechanism that changes the state according to the condition with the behavior as one state.
In Arbor, you can use state machine by adding ArborFSM component to GameObject.
Example: Switch and light
Consider the switch and electric light.
- If the switch is off, the light goes out.
- If the switch is on, the light turns on.
- The state of the light switches with the switch as a condition.
Temporarily assembling with ArborFSM results in the following.
When a Destroy message is sent, a behavior to give an explosion effect and to destroy the light is temporarily assembled.
We will do detailed comment later.
Node component
The nodes used in the state machine are summarized in the following pages.
Please refer once before explaining each part.
Explanation of examples
Let's take a look at the previous example again.
- “Light Off” state
- First, it starts from the Light Off state of the start state.
- ActivateGameObect changes the Spotlight object to inactive.
Arbor Reference : ActivateGameObject - OnTriggerEnterTransition transitions to the Light On state when an object of the Player tag enters.
Arbor Reference : OnTriggerEnterTransition
(In order to use OnTriggerEnterTransition, you need to set Collider etc. on GameObject with ArborFSM)
- “Light On” state
- ActivateGameObect changes the Spotlight object to active.
- By OnTriggerExitTransition, when an object of the Player tag comes out, it transits to the Light Off state.
Arbor Reference : OnTriggerExitTransition
(In order to use OnTriggerExitTransition, you need to set Collider etc. on GameObject with ArborFSM)
- “Wait Trigger” state
- Since it is resident state, it is always executed regardless of which state is being executed.
- By TriggerTransition, when a Destroy message comes, it transits to the Explosion & Destroy state.
Arbor Reference : TriggerTransition- To send the Trigger message, use SendTrigger.
Arbor Reference : SendTrigger
It uses a SendTrigger from another FSM and indirectly issues a transition instruction.
- To send the Trigger message, use SendTrigger.
- “Explosion & Destroy” statea
- InstantiateGameObject instantiates prefab.
Arbor Reference : InstantiateGameObject
(It is an assumption that you set up particles etc., although nothing is set for the temporary set) - DestroyGameObject destroys the LightFSM object (its own GameObject).
Arbor Reference : DestroyGameObject
- InstantiateGameObject instantiates prefab.
I think that I understand the flow that combines behaviors into state and transitions when it matches the transition condition.
If it is a simple example like this one, I think some people may find it easier to write MonoBehaviour directly,
When multiple states become confused, it will be a great advantage to visualize in graph form.