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!)

Start.PNG

Stop

Stops the finite state machine. (Call Resume to start the machine again)

Stop.PNG

Resume

Resumes the finite state machine, after being stopped. (This should be called after being stopped)

Resume.PNG

Enable Tick

Enables the FSM component's tick function. Also enables input handling.

EnableTick.PNG

Disable Tick

Disables the FSM component's tick function. Also disables input handling.

DisableTick.PNG

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

PushState.PNG

Pop State

Removes a state from the stack, using a name

StateName - The state's name to search for and remove

PopState.PNG

Pop State (Active)

Removes the state that's on the top of the stack (The active state).

PopStateActive.PNG

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

PopStateAndPushState.PNG

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

PopActiveStateAndPushState.PNG

Pop All States Except Active

Removes all states from the stack, except for the active state

PopAllStatesExceptActive.PNG

Pop All States

Removes all states from the stack, except for the initial state

PopAllStates.PNG

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

PopStates.PNG

FSM Owner

The finite state machine owner of this state

FSMOwner.PNG

Actor Owner

The actor that owns this state

ActorOwner.PNG

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)

Exit.PNG

Event Update

This is called every frame when in this state

Update.PNG

Event Handle Input

This is called when any key has been pressed, released, repeated, double-clicked or an axis is moved

HandleInput.PNG

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

DoesStateExist.PNG

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

DoesStateExistInStack.PNG

Is Stack Empty

Returns: True if the stack is empty

IsStackEmpty.PNG

Is Machine Running

Returns: True if this state machine is currently running

IsMachineRunning.PNG

Is Machine Initialized

Returns: True if this state machine has been initialized.

IsMachineInitialized.PNG

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

GetStateFromID.PNG

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

GetStateFromName.PNG

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

GetStateID.PNG

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

GetStateName.PNG

Get State Count

Returns: The number of states that are stored in this state machine

GetStateCount.PNG

Get State Count In Stack

Returns: The number of states that are on the stack at this moment

GetStateCountInStack.PNG

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

GetActiveState.PNG

Get Active State Uptime

Returns: The active state's uptime

GetActiveStateUptime.PNG

Get Active State Frames

Returns:  The active state's frames

GetActiveStateFrames.PNG

Get Active State Name

Returns: The active state's name

GetActiveStateName.PNG

Get Active State ID

Returns: The active state's ID

GetActiveStateID.PNG

Previous State Queries

Get Previous State

Retrieves the previous state

Returns: A pointer to the previous state, if it exists. Otherwise null

GetPreviousState.PNG

Get Previous State Uptime

Returns: The previous state's uptime

GetPreviousStateUptime.PNG

Get Previous State Frames

Returns: The previous state's frames

GetPreviousStateFrames.PNG

Get Previous State Name

Returns: The previous state's name

GetPreviousStateName.PNG

Get Previous State ID

Returns: The previous state's ID

GetPreviousStateID.PNG

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.