Stack-based Hierarchical FSM Plugin for UE4.22+
A Finite State Machine allows you to create clean, maintainable 'non-spaghettified' code. With a stack-based hierarchical implementation, you are able to stack multiple states and remember what state you were in while having greater control in each state.
Looking for the guide? Click here
Available on the Unreal Marketplace
A list of all FSM functions and their purpose
This page contains a list of the FSM functions available to you and what their purpose is.
Controls
Start
Starts the finite state machine. (Do not call in the constructor, the game will crash, must be called in BeginPlay!)
Stop
Stops the finite state machine. (Call Resume to start the machine again)
Resume
Resumes the finite state machine, after being stopped. (This should be called after being stopped)
Enable Tick
Enables the FSM component's tick function. Also enables input handling.
Disable Tick
Disables the FSM component's tick function. Also disables input handling.
Main Interface
Push State
Adds a state to the top of the stack, via the state's name
StateName - The state's name to search for and push
Pop State
Removes a state from the stack, using a name
StateName - The state's name to search for and remove
Pop State (Active)
Removes the state that's on the top of the stack (The active state).
Pop State And Push State
Removes a state from the stack, and pushes a new state on to the stack, using name
StateToPop - The state's name to search for and remove from the stack
StateToPush - The state's name to search for and push on to the stack
Pop Active State And Push State
Removes the active state from the stack, and pushes a new state on to the stack, using name
StateToPush - The state's name to search for and push on to the stack
Pop All States Except Active
Removes all states from the stack, except for the active state
Pop All States
Removes all states from the stack, except for the initial state
Pop States
Removes states from the top of the stack 'Count' times
Count - The number of times to 'pop' from the top of the stack
FSM Owner
The finite state machine owner of this state
Actor Owner
The actor that owns this state
Event Init
This is called when the state object has been created. (The state's custom "BeginPlay" event)
Event Enter
This is called when we first enter this state (When PushState() has been called)
Event Exit
This is called when exiting this state (When PopState() has been called on this state)
Event Update
This is called every frame when in this state
Event Handle Input
This is called when any key has been pressed, released, repeated, double-clicked or an axis is moved
Queries
Does State Exist
Test to see if a state exists in this machine, given a name
StateName - The state's name to search for
Returns: True if state name exists in this machine. Otherwise false
Does State Exist In Stack
Test to see if a state exists in the stack, given a name
StateName - The state's name to search for
Returns: True if state name exists in the stack. Otherwise false
Is Stack Empty
Returns: True if the stack is empty
Is Machine Running
Returns: True if this state machine is currently running
Is Machine Initialized
Returns: True if this state machine has been initialized.
State-Specific Queries
Get State From ID
Retrieves a state using an ID
StateID - The state's ID
Returns: A pointer to the retrieved state, if it exists. Otherwise null
Get State From Name
Retrieves a state using a name
StateName - The state's name
Returns: A pointer to the retrieved state, if it exists. Otherwise null
Get State ID
Retrieves the ID of a state, given a name
StateName - The state's name to search for
Returns: The ID of the state, if it exists. Otherwise -1
Get State Name
Retrieves the name of a state, given an ID
ID - The state's ID to search for
Returns: The name of the state, if it exists. Otherwise NAME_None
Get State Count
Returns: The number of states that are stored in this state machine
Get State Count In Stack
Returns: The number of states that are on the stack at this moment
Active State Queries
Get Active State
Retrieves the active state from the stack
Returns: A pointer to the active state, if it exists. Otherwise null
Get Active State Uptime
Returns: The active state's uptime
Get Active State Frames
Returns: The active state's frames
Get Active State Name
Returns: The active state's name
Get Active State ID
Returns: The active state's ID
Previous State Queries
Get Previous State
Retrieves the previous state
Returns: A pointer to the previous state, if it exists. Otherwise null
Get Previous State Uptime
Returns: The previous state's uptime
Get Previous State Frames
Returns: The previous state's frames
Get Previous State Name
Returns: The previous state's name
Get Previous State ID
Returns: The previous state's ID
I need help!
If you are still having issues getting this plugin to work, feel free to join the Discord Support Server and report what the issue is in the #stack-based-fsm channel.