Character state
A state is a component that defines the gameplay logic associated with the CharacterActor component.
State vs Monobehaviour
States work in the same way monobehaviours work:
They process some task over and over again in a frame by frame basis (the behaviour).
They are updated by a controller of some kind (the state controller).
The big advantage of putting code inside a state, rather than using a monobehaviour, is:
The controller communicates better between other states, allowing you to create transitions between them.
Since they are part of a FSM, only one of them will be running at a time.
The controller is designed with a few components in mind (other states, animator, actions, character actor, etc.).
State behaviour
Every state presents its own behaviour, and can be implemented through its abstracts and virtual methods. In order to define the state behaviour you'll need to override some specific methods from the CharacterState component. For instance, if you want to create your own "exit behaviour" (executed when leaving a state) you can do something like this:
Transitions
A transition, from a code point of view, consists of a set of conditions required by the state machine when switching from one state to another. This state machine in particular divides a transition into two parts, one for the current state ("from state") and one for the potential next state ("to state").
From state
State where the transition originates.
To state
State where the transition ends.
These transitions are called Exit transition and Enter transition.
Exit transition
This is the part of the transition that is evaluated first, when trying to exit the current state (hence its name).
Enter transition
This is the part of the transition that is evaluated secondly, when trying to enter the next state (hence its name).
Exit Transition
Inside CheckExitTransition, you would normally add potential target states to a queue. Note that there might be more than one potential state (candidate) at the same time. This is why there is a queue of states.
Example:
Enter transition
CheckEnterTransition will be called for all the states contained inside the queue. If this method returns true, that means the transition has been validated.
Example:
The following transition should be validated only if the fromState state is of type ExampleState:
Last updated