A State, derived from the BP_BaseState class, defines what a state does when entering a state, ending a state, & can manage the transition between a finite number of states. Because all state logic can be created inside state objects, this enables the creation of multiple systems which are like modular pieces of code that can be modified or replaced as needed in child/derived classes.
Defining Default States
After adding the State Manager Component to an actor, the default states can be defined by adding them to the “States Classes” array in the details panel for the component. You can create any number of state classes needed for the actor. You can use states without first creating a class. Simply call “Enter State” & specify the state tag without creating a state class. A state class will be created for you at runtime & a tag will be assigned to the state.
Basic Usage
A the flow of logic execution for a State after being added to an actor’s State Manager component is like this:
CanEnterState? - This function will perform a condition check that will check if the state can run before the State is executed.
EnterState - Executes logic associated with the State.
This is the function that users need to override in order to create custom functionality for a State.
End State - Ends the state when it is finished executing. Typically used to call any functionality needed to set code back or disable certain things when a State ends.
This is the function that users need to override in order to call logic that needs to run when ending the state.
Run State Machine - Executes logic associated with transitioning state between a finite number of states.
This if the function that users need to override in order to call logic that transitions between states. It is up to the user to write the conditions that transition between states & call “Enter State” on the desired state.
Tags
Gameplay Tags can be used to define the tag of the state which will help when searching for the state by tag or trying to run the state by tag.
Gameplay tags also add a lot of flexibility & power to the system. Any number of States can be created & assigned their own gameplay tag. Which will allow you to create any number of states & find them by tag. The use of gameplay tags will also allow you to easily have different states for different actors. For example, you can have a projectile with a state, a character with a state, & any other actor that requires the use of states. The projectile could have Projectile.State tag & the character could have a Character.State tag. Making it easy to distinguish between for designers.