Skip to content

FSMStateMachine

Module: SMSystem

#include <SMStateMachine.h>

Inherits from FSMState_Base, FSMNode_Base

Description

struct FSMStateMachine;

State machines contain states and transitions. When a transition succeeds the current state advances to the next. FSMStateMachine is also considered a state since it inherits from FSMState_Base, making it possible to nest state machines.

When configured as a reference this will defer handling to the SMInstance (or in some cases the RootStateMachine) of the referenced Blueprint.

Public Classes

Name
struct FGetNodeArgs
struct FStateScopingArgs

Public Functions

Name
FSMStateMachine()
virtual void Initialize(UObject * Instance) override
virtual void InitializeGraphFunctions() override
virtual void Reset() override
virtual void ResetReadStates() override
virtual bool StartState() override
virtual bool UpdateState(float DeltaSeconds) override
virtual bool EndState(float DeltaSeconds, const FSMTransition * TransitionToTake =nullptr) override
virtual void ExecuteInitializeNodes() override
virtual void ExecuteShutdownNodes() override
virtual void OnStartedByInstance(USMInstance * Instance) override
virtual void OnStoppedByInstance(USMInstance * Instance) override
virtual void CalculatePathGuid(TMap< FString, int32 > & InOutMappedPaths, bool bUseGuidCache =false) override
virtual void RunConstructionScripts() override
virtual bool IsInEndState() const override
virtual bool IsEndState() const override
virtual bool IsStateMachine() const override
virtual bool IsNodeInstanceClassCompatible(UClass * NewNodeInstanceClass) const override
virtual USMNodeInstance * GetNodeInstance() const override
virtual USMNodeInstance * GetOrCreateNodeInstance() override
virtual bool CanEverCreateNodeInstance() const override
virtual UClass * GetDefaultNodeInstanceClass() const override
virtual FSMNode_Base * GetOwnerNode() const override
virtual void SetStartTime(const FDateTime & InStartTime) override
virtual void SetEndTime(const FDateTime & InEndTime) override
virtual void SetServerTimeInState(float InTime) override
bool IsStateMachineInEndState() const
bool HasStateMachineReachedEndStateForRun() const
void AddState(FSMState_Base * State)
void AddTransition(FSMTransition * Transition)
void AddInitialState(FSMState_Base * State)
void AddTemporaryInitialState(FSMState_Base * State)
void ClearTemporaryInitialStates(bool bRecursive =false)
void SetFromTemporaryInitialStates()
bool ContainsActiveState(FSMState_Base * StateToCheck) const
bool HasActiveStates() const
bool HasTemporaryEntryStates() const
FSMState_Base * GetSingleActiveState() const
TArray< FSMState_Base * > GetActiveStates() const
TArray< FSMState_Base * > GetAllNestedActiveStates() const
TArray< FSMNode_Base * > GetAllNodes(const FGetNodeArgs & InArgs =FGetNodeArgs()) const
TArray< FSMNode_Base * > GetAllNodes(bool bIncludeNested, bool bForwardToReference =false) const
const TArray< FSMState_Base * > & GetStates() const
const TArray< FSMTransition * > & GetTransitions() const
const TArray< FSMState_Base * > & GetEntryStates() const
TArray< FSMState_Base * > GetInitialStates() const
FSMState_Base * GetSingleInitialState() const
FSMState_Base * GetSingleInitialTemporaryState() const
TArray< FSMState_Base * > GetAllNestedInitialTemporaryStates() const
FSMState_Base * FindState(const FGuid & StateGuid) const
void SetNetworkedConditions(TScriptInterface< ISMStateMachineNetworkedInterface > InNetworkInterface, bool bEvaluateTransitions, bool bTakeTransitions, bool bCanExecuteStateLogic)
void ProcessStates(float DeltaSeconds, bool bForceTransitionEvaluationOnly =false, const FGuid & InCurrentRunGuid =FGuid(), const FStateScopingArgs & InStateScopingArgs =FStateScopingArgs())
bool ProcessTransition(FSMTransition * Transition, FSMState_Base * SourceState, FSMState_Base * DestinationState, const FSMTransitionTransaction * Transaction, float DeltaSeconds, FDateTime * CurrentTime =nullptr)
bool EvaluateAndTakeTransitionChain(FSMTransition * InFirstTransition)
bool TakeTransitionChain(const TArray< FSMTransition * > & InTransitionChain)
bool TryStartState(FSMState_Base * InState, bool * bOutSafeToCheckTransitions =nullptr)
bool TryTakeTransitionChain(const TArray< FSMTransition * > & InTransitionChain, float DeltaSeconds, bool bStateJustStarted =false, FSMState_Base ** OutDestinationState =nullptr)
bool CanProcessExternalTransition() const
bool IsWaitingForUpdate() const
void SetReuseCurrentState(bool bValue, bool bOnlyWhenNotInEndState)
bool CanReuseCurrentState() const
void SetClassReference(UClass * ClassReference)
UClass * GetClassReference() const
void SetInstanceReference(USMInstance * InstanceReference)
USMInstance * GetInstanceReference() const
void SetReferencedTemplateName(const FName & Name)
const FName & GetReferencedTemplateName() const
void SetReferencedBy(USMInstance * FromInstance, FSMStateMachine * FromStateMachine)
USMInstance * GetReferencedByInstance() const
FSMStateMachine * GetReferencedByStateMachine() const
void SetDynamicReferenceVariableName(const FName & InVariableName)
const FName & GetDynamicReferenceVariableName() const
bool IsDynamicReference() const
bool IsNetworked() const
ISMStateMachineNetworkedInterface * TryGetNetworkInterfaceIfNetworked() const
const TMap< FString, FSMState_Base * > & GetStateNameMap() const
void AddActiveState(FSMState_Base * State)
void RemoveActiveState(FSMState_Base * State)
virtual void ResetGeneratedValues() override

Protected Functions

Name
virtual void InitializeFunctionHandlers() override
virtual void NotifyInstanceStateHasStarted() override
void SetCurrentState(FSMState_Base * ToState, FSMState_Base * FromState, FSMState_Base * SourceState =nullptr)
void TryNotifyEndStateReached()

Public Attributes

Name
uint8 bHasAdditionalLogic
uint8 bReuseCurrentState
uint8 bOnlyReuseIfNotEndState
uint8 bAllowIndependentTick
uint8 bCallReferenceTickOnManualUpdate
uint8 bWaitForEndState

Additional inherited members

Public Functions inherited from FSMState_Base

Name
virtual void UpdateReadStates() override
FSMState_Base()
const TArray< FSMTransition * > & GetOutgoingTransitions() const
const TArray< FSMTransition * > & GetIncomingTransitions() const
void GetAllTransitionChains(TArray< FSMTransition * > & OutTransitions) const
virtual bool GetValidTransition(TArray< TArray< FSMTransition * > > & Transitions)
virtual bool HasUpdated() const
virtual bool IsConduit() const
bool IsRootNode() const
float GetActiveTime() const
void SetCanExecuteLogic(bool bValue)
bool CanExecuteLogic() const
virtual bool CanExecuteGraphProperties(uint32 OnEvent, const USMStateInstance_Base * ForTemplate) const override
bool CanEvaluateTransitionsOnTick() const
void SortTransitions()
void SetTransitionToTake(const FSMTransition * Transition)
const FSMTransition * GetTransitionToTake() const
void SetPreviousActiveState(FSMState_Base * InPreviousState)
void SetPreviousActiveTransition(FSMTransition * InPreviousTransition)
FSMState_Base * GetPreviousActiveState() const
FSMTransition * GetPreviousActiveTransition() const
void NotifyOfParallelReentry(bool bValue =true)
bool HasBeenReenteredFromParallelState() const
bool IsStateEnding() const
const FDateTime & GetStartTime() const
const FDateTime & GetEndTime() const
double GetStartCycle() const

Protected Functions inherited from FSMState_Base

Name
void AddOutgoingTransition(FSMTransition * Transition)
void AddIncomingTransition(FSMTransition * Transition)
void InitializeTransitions()
void ShutdownTransitions()
virtual void FirePreStartEvents()
virtual void FirePostStartEvents()

Public Attributes inherited from FSMState_Base

Name
uint16 bIsRootNode
uint16 bAlwaysUpdate
uint16 bEvalTransitionsOnStart
uint16 bDisableTickTransitionEvaluation
uint16 bStayActiveOnStateChange
uint16 bAllowParallelReentry
uint16 bCanBeEndState

Protected Attributes inherited from FSMState_Base

Name
uint16 bReenteredByParallelState
uint16 bCanExecuteLogic
uint16 bIsStateEnding
FSMState_Base * PreviousActiveState
FSMTransition * PreviousActiveTransition
FDateTime StartTime
FDateTime EndTime

Friends inherited from FSMState_Base

Name
struct FSMTransition(FSMTransition )

Public Functions inherited from FSMNode_Base

Name
const FSMNode_FunctionHandlers * GetFunctionHandlers() const
virtual void UpdateReadStates()
FSMNode_Base()
virtual ~FSMNode_Base() =default
FSMNode_Base(const FSMNode_Base & Node) =default
bool HaveGraphFunctionsInitialized() const
bool IsInitializedForRun() const
const FGuid & GetNodeGuid() const
void GenerateNewNodeGuid()
const FGuid & GetGuid() const
FString GetGuidPath(TMap< FString, int32 > & InOutMappedPaths) const
FGuid CalculatePathGuidConst() const
void GenerateNewNodeGuidIfNotSet()
void SetNodeGuid(const FGuid & NewGuid)
void SetOwnerNodeGuid(const FGuid & NewGuid)
const FGuid & GetOwnerNodeGuid() const
void SetOwnerNode(FSMNode_Base * Owner)
USMInstance * GetOwningInstance() const
void CreateNodeInstance()
void CreateStackInstances()
void SetNodeInstanceClass(UClass * NewNodeInstanceClass)
const TArray< TObjectPtr< USMNodeInstance > > & GetStackInstancesConst() const
TArray< TObjectPtr< USMNodeInstance > > & GetStackInstances()
USMNodeInstance * GetNodeInStack(int32 Index) const
UClass * GetNodeInstanceClass() const
bool IsUsingDefaultNodeClass() const
void AddVariableGraphProperty(const FSMGraphProperty_Base_Runtime & GraphProperty, const FGuid & OwningTemplateGuid)
void SetNodeName(const FString & Name)
const FString & GetNodeName() const
void SetTemplateName(const FName & Name)
FName GetTemplateName(USMNodeInstance * InNodeInstance =nullptr) const
void AddStackTemplateName(const FName & Name, UClass * TemplateClass)
virtual bool IsActive() const
float GetServerTimeInState() const
virtual bool CanExecuteGraphProperties(uint32 OnEvent, const class USMStateInstance_Base * ForTemplate) const
virtual bool TryExecuteGraphProperties(uint32 OnEvent)
void ExecuteGraphProperties(USMNodeInstance * ForNodeInstance, const FGuid * ForTemplateGuid)
const TArray< FSMGraphProperty_Base_Runtime * > & GetGraphProperties() const
const TMap< FGuid, FSMGraphPropertyTemplateOwner > & GetTemplateGraphProperties() const
virtual void TryResetVariables()
virtual bool IsDebugActive() const
virtual bool WasDebugActive() const
virtual void EditorShutdown()
FName GetNodeGuidPropertyName()

Protected Functions inherited from FSMNode_Base

Name
virtual void PrepareGraphExecution()
virtual void SetActive(bool bValue)
void CreateGraphProperties()
void CreateGraphPropertiesForTemplate(USMNodeInstance * Template, const TMap< FGuid, FSMGraphProperty_Base_Runtime * > & MappedGraphPropertyInstances)

Public Attributes inherited from FSMNode_Base

Name
bool bValidateGuids
float TimeInState
bool bIsInEndState
bool bHasUpdated
int32 DuplicateId
FVector2D NodePosition
uint8 bHasInputEvents
bool bWasActive

Protected Attributes inherited from FSMNode_Base

Name
FSMNode_FunctionHandlers * FunctionHandlers
FGuid Guid
FGuid OwnerGuid
FGuid PathGuid
FSMNode_Base * OwnerNode
FString NodeName
FName TemplateName
TArray< FName > StackTemplateNames
TArray< TObjectPtr< USMNodeInstance > > StackNodeInstances
TArray< TObjectPtr< UClass > > NodeStackClasses
TObjectPtr< USMInstance > OwningInstance
TObjectPtr< USMNodeInstance > NodeInstance
TArray< FSMGraphProperty_Base_Runtime * > GraphProperties
TMap< FGuid, FSMGraphPropertyTemplateOwner > TemplateVariableGraphProperties
TObjectPtr< UClass > NodeInstanceClass

Friends inherited from FSMNode_Base

Name
class FSMEditorConstructionManager

Public Functions Documentation

function FSMStateMachine

FSMStateMachine()

function Initialize

virtual void Initialize(
    UObject * Instance
) override

Initialize specific properties and node instances.

Reimplements: FSMState_Base::Initialize


function InitializeGraphFunctions

virtual void InitializeGraphFunctions() override

Initialize all graph evaluator functions. Must be called from GameThread!

Reimplements: FSMState_Base::InitializeGraphFunctions


function Reset

virtual void Reset() override

Resets persistent data.

Reimplements: FSMState_Base::Reset


function ResetReadStates

virtual void ResetReadStates() override

Reimplements: FSMState_Base::ResetReadStates


function StartState

virtual bool StartState() override

Sets the state as active and begins execution.

Reimplements: FSMState_Base::StartState


function UpdateState

virtual bool UpdateState(
    float DeltaSeconds
) override

Runs the update execution.

Reimplements: FSMState_Base::UpdateState


function EndState

virtual bool EndState(
    float DeltaSeconds,
    const FSMTransition * TransitionToTake =nullptr
) override

Runs the end state execution. Transition to take is so the state knows where it is going only.

Reimplements: FSMState_Base::EndState


function ExecuteInitializeNodes

virtual void ExecuteInitializeNodes() override

Reimplements: FSMState_Base::ExecuteInitializeNodes


function ExecuteShutdownNodes

virtual void ExecuteShutdownNodes() override

Reimplements: FSMNode_Base::ExecuteShutdownNodes


function OnStartedByInstance

virtual void OnStartedByInstance(
    USMInstance * Instance
) override

Called when the blueprint owning this node is started.

Reimplements: FSMState_Base::OnStartedByInstance


function OnStoppedByInstance

virtual void OnStoppedByInstance(
    USMInstance * Instance
) override

Called when the blueprint owning this node has stopped.

Reimplements: FSMState_Base::OnStoppedByInstance


function CalculatePathGuid

virtual void CalculatePathGuid(
    TMap< FString, int32 > & InOutMappedPaths,
    bool bUseGuidCache =false
) override

Calculate the value returned from GetGuid(). Gets all owner nodes and builds a path to this node. Hashes the path and sets PathGuid.

Reimplements: FSMNode_Base::CalculatePathGuid


function RunConstructionScripts

virtual void RunConstructionScripts() override

Reimplements: FSMNode_Base::RunConstructionScripts


function IsInEndState

virtual bool IsInEndState() const override

Deprecated:

Use IsStateMachineInEndState() instead.

Reimplements: FSMState_Base::IsInEndState


function IsEndState

virtual bool IsEndState() const override

If the state itself is an end state.

Reimplements: FSMState_Base::IsEndState


function IsStateMachine

inline virtual bool IsStateMachine() const override

Easy way to check if this state struct is a state machine.

Reimplements: FSMState_Base::IsStateMachine


function IsNodeInstanceClassCompatible

virtual bool IsNodeInstanceClassCompatible(
    UClass * NewNodeInstanceClass
) const override

Derived nodes should overload and check for the correct type.

Reimplements: FSMState_Base::IsNodeInstanceClassCompatible


function GetNodeInstance

virtual USMNodeInstance * GetNodeInstance() const override

Return the current node instance. Only valid after initialization and may be nullptr.

Reimplements: FSMNode_Base::GetNodeInstance


function GetOrCreateNodeInstance

virtual USMNodeInstance * GetOrCreateNodeInstance() override

Create a node instance on demand if needed. Only required for default node classes. Initialization should be completed before calling.

Reimplements: FSMNode_Base::GetOrCreateNodeInstance


function CanEverCreateNodeInstance

inline virtual bool CanEverCreateNodeInstance() const override

If the node can at some point create a node instance.

Reimplements: FSMNode_Base::CanEverCreateNodeInstance


function GetDefaultNodeInstanceClass

virtual UClass * GetDefaultNodeInstanceClass() const override

The default node instance class. Each derived node class needs to implement.

Reimplements: FSMState_Base::GetDefaultNodeInstanceClass


function GetOwnerNode

virtual FSMNode_Base * GetOwnerNode() const override

The node directly owning this node. Should be a StateMachine.

Reimplements: FSMNode_Base::GetOwnerNode


function SetStartTime

virtual void SetStartTime(
    const FDateTime & InStartTime
) override

Set the local start time.

Reimplements: FSMState_Base::SetStartTime


function SetEndTime

virtual void SetEndTime(
    const FDateTime & InEndTime
) override

Set the local end time.

Reimplements: FSMState_Base::SetEndTime


function SetServerTimeInState

virtual void SetServerTimeInState(
    float InTime
) override

Set the time in state as recorded from the server.

Reimplements: FSMNode_Base::SetServerTimeInState


function IsStateMachineInEndState

bool IsStateMachineInEndState() const

If this state machine is in an end state or has no active states.


function HasStateMachineReachedEndStateForRun

inline bool HasStateMachineReachedEndStateForRun() const

If the state machine has reached an end state for its current run. This can be set when an active state's IsEndState() is true, or if the state machine has deactivated all states.


function AddState

void AddState(
    FSMState_Base * State
)

Add a state to this State Machine.


function AddTransition

void AddTransition(
    FSMTransition * Transition
)

Add a transition to this State Machine.


function AddInitialState

void AddInitialState(
    FSMState_Base * State
)

The first state to execute. Even with parallel states there is always a single root entry point.


function AddTemporaryInitialState

void AddTemporaryInitialState(
    FSMState_Base * State
)

These states will replace the initial state, but once started will be cleared.

Parameters:

State
A non null state will be added to the set as long as it exists within the state machine. A null value is ignored.

function ClearTemporaryInitialStates

void ClearTemporaryInitialStates(
    bool bRecursive =false
)

Removes all temporary initial states.


function SetFromTemporaryInitialStates

void SetFromTemporaryInitialStates()

Loads temporary states if not already loaded and start them.


function ContainsActiveState

bool ContainsActiveState(
    FSMState_Base * StateToCheck
) const

Checks if the given state is contained within the active states.


function HasActiveStates

bool HasActiveStates() const

Checks if there are any active states.


function HasTemporaryEntryStates

bool HasTemporaryEntryStates() const

Checks if there any temporary initial states set.


function GetSingleActiveState

FSMState_Base * GetSingleActiveState() const

The current state of this State Machine. In the event of multiple parallel states the first active state is returned.


function GetActiveStates

TArray< FSMState_Base * > GetActiveStates() const

Returns a copy of all active states specific to this FSM making it safe for iteration modification.


function GetAllNestedActiveStates

TArray< FSMState_Base * > GetAllNestedActiveStates() const

Return a list of all active states recursively searching nested state machines.


function GetAllNodes

TArray< FSMNode_Base * > GetAllNodes(
    const FGetNodeArgs & InArgs =FGetNodeArgs()
) const

Retrieve nodes of all types.

Parameters:

InArgs
Arguments to filter out nodes.

function GetAllNodes

TArray< FSMNode_Base * > GetAllNodes(
    bool bIncludeNested,
    bool bForwardToReference =false
) const

Deprecated:

Use GetAllNodes() that takes the FGetNodeArgs arguments instead. bForwardToReference is no longer supported.


function GetStates

const TArray< FSMState_Base * > & GetStates() const

Retrieve nodes of all state types.


function GetTransitions

const TArray< FSMTransition * > & GetTransitions() const

Retrieve nodes of only transitions.


function GetEntryStates

const TArray< FSMState_Base * > & GetEntryStates() const

Returns only the original entry states.


function GetInitialStates

TArray< FSMState_Base * > GetInitialStates() const

The entry state of this state machine. Returns either the temporary or default. Possible to be greater than 0 when loading from temporary parallel states.


function GetSingleInitialState

FSMState_Base * GetSingleInitialState() const

Returns either null or the first initial state. Only use this if you know the FSM doesn't have parallel states.


function GetSingleInitialTemporaryState

FSMState_Base * GetSingleInitialTemporaryState() const

Returns either null or the first initial temporary state. Only use this if you know the FSM doesn't have parallel states.


function GetAllNestedInitialTemporaryStates

TArray< FSMState_Base * > GetAllNestedInitialTemporaryStates() const

Returns all nested temporary states if they are set.


function FindState

FSMState_Base * FindState(
    const FGuid & StateGuid
) const

Linear search recursively through all states and state machines.


function SetNetworkedConditions

void SetNetworkedConditions(
    TScriptInterface< ISMStateMachineNetworkedInterface > InNetworkInterface,
    bool bEvaluateTransitions,
    bool bTakeTransitions,
    bool bCanExecuteStateLogic
)

Determine how to process transitions and states in different environments.


function ProcessStates

void ProcessStates(
    float DeltaSeconds,
    bool bForceTransitionEvaluationOnly =false,
    const FGuid & InCurrentRunGuid =FGuid(),
    const FStateScopingArgs & InStateScopingArgs =FStateScopingArgs()
)

Determine if the current state should be stopped or started or evaluate a transition.

Parameters:

DeltaSeconds
Time since last update.
bForceTransitionEvaluationOnly
The update (Tick) logic for a state won't be called unless the state is ending and bAlwaysUpdate is checked. Start and End may still be called.
InCurrentRunGuid
A guid unique to this call stack. Leave empty, for internal use.
InStateScopingArgs
Limit state processing to select states.

function ProcessTransition

bool ProcessTransition(
    FSMTransition * Transition,
    FSMState_Base * SourceState,
    FSMState_Base * DestinationState,
    const FSMTransitionTransaction * Transaction,
    float DeltaSeconds,
    FDateTime * CurrentTime =nullptr
)

Attempt to take a transition. Does not evaluate the transition. Returns true if successful.

Parameters:

Transition
The transition to process.
SourceState
The original state to transition from.
DestinationState
the final state to transition to.
Transaction
A network transaction if one exists. May be null.
DeltaSeconds
The time in seconds since the last update.
CurrentTime
The current UTC time. Only utilized in networked environments for recording time stamps.

function EvaluateAndTakeTransitionChain

bool EvaluateAndTakeTransitionChain(
    FSMTransition * InFirstTransition
)

Evaluate an entire transition chain discovering the path to take. If an entire chain passes then switch to the destination state.

A transition chain is the first path that evaluates to true between two states, consisting of all transitions and conduits that are configured to eval with transitions.

This method fails if the state machine isn't state change authoritative. The destination state won't become active if this state machine doesn't have local state change authority.

If the method passes each transition taken will be replicated in order.

Parameters:

InFirstTransition
The transition struct, which should be the first part of a transition chain.

Return: True if the chain succeeded evaluation.


function TakeTransitionChain

bool TakeTransitionChain(
    const TArray< FSMTransition * > & InTransitionChain
)

Take a transition chain. Does not evaluate, but adheres to all normal state change behavior.

Parameters:

InTransitionChain
The transition chain to take.

Return: True if taken.


function TryStartState

bool TryStartState(
    FSMState_Base * InState,
    bool * bOutSafeToCheckTransitions =nullptr
)

Try starting the given state.

Parameters:

InState
The state to start.
bOutSafeToCheckTransitions
[Out] If it is safe to check transitions on this state this frame.

Return: True if the state was started, false if it was already started or cannot start.


function TryTakeTransitionChain

bool TryTakeTransitionChain(
    const TArray< FSMTransition * > & InTransitionChain,
    float DeltaSeconds,
    bool bStateJustStarted =false,
    FSMState_Base ** OutDestinationState =nullptr
)

Try taking the given transition chain to the end destination state.

Parameters:

InTransitionChain
A single transition, or multiple transitions with conduits.
DeltaSeconds
Delta seconds to apply to ProcessTransition.
bStateJustStarted
If the source state has started this frame.
OutDestinationState
[Out] The destination state at the end of chain, only set if the transition chain was taken.

Return: True if the transition chain was taken, false if not.


function CanProcessExternalTransition

bool CanProcessExternalTransition() const

External callers should check this before calling ProcessTransition().


function IsWaitingForUpdate

inline bool IsWaitingForUpdate() const

State Machine is currently waiting for a transition update from the server.


function SetReuseCurrentState

void SetReuseCurrentState(
    bool bValue,
    bool bOnlyWhenNotInEndState
)

When true the current state is reused on exit/reentry. When false the current state is cleared on end and the initial state used on reentry.


function CanReuseCurrentState

bool CanReuseCurrentState() const

Is the current state reused or reset on exit/reentry.


function SetClassReference

void SetClassReference(
    UClass * ClassReference
)

function GetClassReference

inline UClass * GetClassReference() const

function SetInstanceReference

void SetInstanceReference(
    USMInstance * InstanceReference
)

function GetInstanceReference

inline USMInstance * GetInstanceReference() const

function SetReferencedTemplateName

void SetReferencedTemplateName(
    const FName & Name
)

function GetReferencedTemplateName

inline const FName & GetReferencedTemplateName() const

function SetReferencedBy

void SetReferencedBy(
    USMInstance * FromInstance,
    FSMStateMachine * FromStateMachine
)

function GetReferencedByInstance

inline USMInstance * GetReferencedByInstance() const

The instance referencing this state machine.


function GetReferencedByStateMachine

inline FSMStateMachine * GetReferencedByStateMachine() const

The exact state machine referencing this, if any.


function SetDynamicReferenceVariableName

inline void SetDynamicReferenceVariableName(
    const FName & InVariableName
)

Set a variable name of the owning SMInstance to use for a dynamic class lookup.


function GetDynamicReferenceVariableName

inline const FName & GetDynamicReferenceVariableName() const

Get a variable name to use with the owning SMInstance for dynamic class lookup.


function IsDynamicReference

inline bool IsDynamicReference() const

If this is a dynamic state machine reference.


function IsNetworked

inline bool IsNetworked() const

True only if this FSM is networked.


function TryGetNetworkInterfaceIfNetworked

ISMStateMachineNetworkedInterface * TryGetNetworkInterfaceIfNetworked() const

Find the network interface if one is assigned and active.


function GetStateNameMap

const TMap< FString, FSMState_Base * > & GetStateNameMap() const

All contained states mapped out by their name, limited to this FSM scope.


function AddActiveState

void AddActiveState(
    FSMState_Base * State
)

Forcibly add an active state.

Parameters:

State
The state to add to the active list.

function RemoveActiveState

void RemoveActiveState(
    FSMState_Base * State
)

Forcibly remove an active state.

Parameters:

State
The state to remove from the active list.

function ResetGeneratedValues

virtual void ResetGeneratedValues() override

Reset any values set from state machine generation.

Reimplements: FSMState_Base::ResetGeneratedValues


Protected Functions Documentation

function InitializeFunctionHandlers

virtual void InitializeFunctionHandlers() override

Map the FunctionHandler pointer. Must be implemented per child struct!

Reimplements: FSMNode_Base::InitializeFunctionHandlers


function NotifyInstanceStateHasStarted

virtual void NotifyInstanceStateHasStarted() override

Call the owning instance letting it know this state has started.

Reimplements: FSMState_Base::NotifyInstanceStateHasStarted


function SetCurrentState

void SetCurrentState(
    FSMState_Base * ToState,
    FSMState_Base * FromState,
    FSMState_Base * SourceState =nullptr
)

Switches the current state and notifies the owning instance.

Parameters:

ToState
The state we should be switching to. May be null.
FromState
The state we are switching from. If not null it will be removed from the active list if bStayActiveOnStateChange is false.
SourceState
The original source state we are transitioning from. This can be different from the FromState if transition conduits are involved.

function TryNotifyEndStateReached

void TryNotifyEndStateReached()

Check if an end state has been reached, fire notifications, and traverse any owners that are waiting for an end state.


Public Attributes Documentation

variable bHasAdditionalLogic

uint8 bHasAdditionalLogic;

If this has additional logic associated with it.


variable bReuseCurrentState

uint8 bReuseCurrentState;

The current state is not cleared on end and will be resumed on start.


variable bOnlyReuseIfNotEndState

uint8 bOnlyReuseIfNotEndState;

Don't reuse if the state machine is in an end state.


variable bAllowIndependentTick

uint8 bAllowIndependentTick;

Allows the state machine reference to tick on its own.


variable bCallReferenceTickOnManualUpdate

uint8 bCallReferenceTickOnManualUpdate;

Notifies instance to call tick on manual update. Only valid for references.


variable bWaitForEndState

uint8 bWaitForEndState;

Wait for an end state to be hit before evaluating transitions or being considered an end state itself.


Private Attributes Documentation

variable NetworkedInterface

TScriptInterface< ISMStateMachineNetworkedInterface > NetworkedInterface;

variable States

TArray< FSMState_Base * > States;

variable Transitions

TArray< FSMTransition * > Transitions;

variable EntryStates

TArray< FSMState_Base * > EntryStates;

The default root entry point.


variable TemporaryEntryStates

TArray< FSMState_Base * > TemporaryEntryStates;

Entry states that are temporary and used for loading purposes.


variable ActiveStates

TArray< FSMState_Base * > ActiveStates;

In most cases this should be of size 0 or 1. Greater than 1 implies the sm is configured for multiple active states. Array container needed for exact order when adding parallel states. O(n) operations should be acceptable for average number of active states and only on state changes.


variable StateNameMap

TMap< FString, FSMState_Base * > StateNameMap;

All contained states, mapped by their name.


variable ProcessingStates

TMap< FGuid, TSet< FSMState_Base * > > ProcessingStates;

Keeps track of states currently processing for the given FSM scope. Helps with possible infinite recursion when using multiple states that can re-enter each other.


variable ReferencedStateMachineClass

TObjectPtr< UClass > ReferencedStateMachineClass;

variable ReferencedTemplateName

FName ReferencedTemplateName;

The name of a template archetype to use when constructing a reference. This allows default values be passed into the reference.


variable DynamicStateMachineReferenceVariable

FName DynamicStateMachineReferenceVariable;

The name of a variable stored on the owning SMInstance that should be used to find the class for this reference.


variable ReferencedStateMachine

TObjectPtr< USMInstance > ReferencedStateMachine;

This state machine is referencing an instance.


variable IsReferencedByInstance

TObjectPtr< USMInstance > IsReferencedByInstance;

This state machine is being referenced from an instance.


variable IsReferencedByStateMachine

FSMStateMachine * IsReferencedByStateMachine;

The state machine referencing this state machine, if any.


variable TimeSpentWaitingForUpdate

float TimeSpentWaitingForUpdate;

Current time spent waiting for an update.


variable bWaitingForTransitionUpdate

uint8 bWaitingForTransitionUpdate;

Is currently waiting for an update.


variable bCanEvaluateTransitions

uint8 bCanEvaluateTransitions;

Can this instance even evaluate transitions.


variable bCanTakeTransitions

uint8 bCanTakeTransitions;

Once evaluated can this instance take the transition.


variable bHasReachedEndStateForRun

uint8 bHasReachedEndStateForRun;

True if the state machine has reached an end state at least once and is reset on node initialize.