Skip to content

FSMState_Base

Module: SMSystem

#include <SMState.h>

Inherits from FSMNode_Base

Inherited by FSMConduit, FSMState, FSMStateMachine

Description

struct FSMState_Base;

The base class for all state typed nodes. This should never be instantiated by itself but inherited by children.

Public Functions

Name
virtual void UpdateReadStates() override
virtual void ResetReadStates()
FSMState_Base()
virtual void Initialize(UObject * Instance) override
virtual void InitializeGraphFunctions() override
virtual void Reset() override
virtual bool IsNodeInstanceClassCompatible(UClass * NewNodeInstanceClass) const override
virtual UClass * GetDefaultNodeInstanceClass() const override
virtual void ExecuteInitializeNodes() override
const TArray< FSMTransition * > & GetOutgoingTransitions() const
const TArray< FSMTransition * > & GetIncomingTransitions() const
void GetAllTransitionChains(TArray< FSMTransition * > & OutTransitions) const
virtual bool StartState()
virtual bool UpdateState(float DeltaSeconds)
virtual bool EndState(float DeltaSeconds, const FSMTransition * TransitionToTake =nullptr)
virtual void OnStartedByInstance(USMInstance * Instance) override
virtual void OnStoppedByInstance(USMInstance * Instance) override
virtual bool GetValidTransition(TArray< TArray< FSMTransition * > > & Transitions)
virtual bool IsEndState() const
virtual bool IsInEndState() const
virtual bool HasUpdated() const
virtual bool IsStateMachine() 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
virtual void SetStartTime(const FDateTime & InStartTime)
virtual void SetEndTime(const FDateTime & InEndTime)
double GetStartCycle() const
virtual void ResetGeneratedValues() override

Protected Functions

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

Public Attributes

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

Protected Attributes

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

Friends

Name
struct FSMTransition(FSMTransition )

Additional inherited members

Public Functions inherited from FSMNode_Base

Name
const FSMNode_FunctionHandlers * GetFunctionHandlers() const
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
virtual void CalculatePathGuid(TMap< FString, int32 > & InOutMappedPaths, bool bUseGuidCache =false)
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)
virtual FSMNode_Base * GetOwnerNode() const
USMInstance * GetOwningInstance() const
void CreateNodeInstance()
void CreateStackInstances()
virtual void RunConstructionScripts()
void SetNodeInstanceClass(UClass * NewNodeInstanceClass)
virtual USMNodeInstance * GetNodeInstance() const
virtual USMNodeInstance * GetOrCreateNodeInstance()
virtual bool CanEverCreateNodeInstance() const
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
virtual void ExecuteShutdownNodes()
virtual void SetServerTimeInState(float InTime)
float GetServerTimeInState() 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 InitializeFunctionHandlers()
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 UpdateReadStates

virtual void UpdateReadStates() override

Reimplements: FSMNode_Base::UpdateReadStates


function ResetReadStates

virtual void ResetReadStates()

Reimplemented by: FSMStateMachine::ResetReadStates


function FSMState_Base

FSMState_Base()

function Initialize

virtual void Initialize(
    UObject * Instance
) override

Initialize specific properties and node instances.

Reimplements: FSMNode_Base::Initialize

Reimplemented by: FSMConduit::Initialize, FSMState::Initialize, FSMStateMachine::Initialize


function InitializeGraphFunctions

virtual void InitializeGraphFunctions() override

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

Reimplements: FSMNode_Base::InitializeGraphFunctions

Reimplemented by: FSMConduit::InitializeGraphFunctions, FSMState::InitializeGraphFunctions, FSMStateMachine::InitializeGraphFunctions


function Reset

virtual void Reset() override

Resets persistent data.

Reimplements: FSMNode_Base::Reset

Reimplemented by: FSMConduit::Reset, FSMState::Reset, FSMStateMachine::Reset


function IsNodeInstanceClassCompatible

virtual bool IsNodeInstanceClassCompatible(
    UClass * NewNodeInstanceClass
) const override

Derived nodes should overload and check for the correct type.

Reimplements: FSMNode_Base::IsNodeInstanceClassCompatible

Reimplemented by: FSMConduit::IsNodeInstanceClassCompatible, FSMStateMachine::IsNodeInstanceClassCompatible


function GetDefaultNodeInstanceClass

virtual UClass * GetDefaultNodeInstanceClass() const override

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

Reimplements: FSMNode_Base::GetDefaultNodeInstanceClass

Reimplemented by: FSMConduit::GetDefaultNodeInstanceClass, FSMStateMachine::GetDefaultNodeInstanceClass


function ExecuteInitializeNodes

virtual void ExecuteInitializeNodes() override

Reimplements: FSMNode_Base::ExecuteInitializeNodes

Reimplemented by: FSMConduit::ExecuteInitializeNodes, FSMState::ExecuteInitializeNodes, FSMStateMachine::ExecuteInitializeNodes


function GetOutgoingTransitions

inline const TArray< FSMTransition * > & GetOutgoingTransitions() const

The transitions leading out from this state, sorted lowest to highest priority.


function GetIncomingTransitions

inline const TArray< FSMTransition * > & GetIncomingTransitions() const

The transitions leading to this state.


function GetAllTransitionChains

void GetAllTransitionChains(
    TArray< FSMTransition * > & OutTransitions
) const

Returns all connected transitions from this state, including ones connected to transition conduits.


function StartState

virtual bool StartState()

Sets the state as active and begins execution.

Reimplemented by: FSMConduit::StartState, FSMState::StartState, FSMStateMachine::StartState


function UpdateState

virtual bool UpdateState(
    float DeltaSeconds
)

Runs the update execution.

Reimplemented by: FSMConduit::UpdateState, FSMState::UpdateState, FSMStateMachine::UpdateState


function EndState

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

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

Reimplemented by: FSMConduit::EndState, FSMState::EndState, FSMStateMachine::EndState


function OnStartedByInstance

virtual void OnStartedByInstance(
    USMInstance * Instance
) override

Called when the blueprint owning this node is started.

Reimplements: FSMNode_Base::OnStartedByInstance

Reimplemented by: FSMState::OnStartedByInstance, FSMStateMachine::OnStartedByInstance


function OnStoppedByInstance

virtual void OnStoppedByInstance(
    USMInstance * Instance
) override

Called when the blueprint owning this node has stopped.

Reimplements: FSMNode_Base::OnStoppedByInstance

Reimplemented by: FSMState::OnStoppedByInstance, FSMStateMachine::OnStoppedByInstance


function GetValidTransition

virtual bool GetValidTransition(
    TArray< TArray< FSMTransition * > > & Transitions
)

Runs through the transitions executing their graphs until a result is found. Builds an ordered list of transitions to take.

Parameters:

Transitions
Found transitions. 2D Array of valid paths. If the total size is more than one that means these transitions are leading to parallel states. if each path is more than one that means there are transition conduits involved.

Return: True if a valid path is found, false otherwise.

Reimplemented by: FSMConduit::GetValidTransition


function IsEndState

virtual bool IsEndState() const

If the state itself is an end state.

Reimplemented by: FSMStateMachine::IsEndState


function IsInEndState

virtual bool IsInEndState() const

Reimplemented by: FSMStateMachine::IsInEndState


function HasUpdated

virtual bool HasUpdated() const

Has updated at least once.


function IsStateMachine

inline virtual bool IsStateMachine() const

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

Reimplemented by: FSMStateMachine::IsStateMachine


function IsConduit

inline virtual bool IsConduit() const

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

Reimplemented by: FSMConduit::IsConduit


function IsRootNode

inline bool IsRootNode() const

If this node is an initial entry point.


function GetActiveTime

inline float GetActiveTime() const

Current time in seconds this state has been active.


function SetCanExecuteLogic

void SetCanExecuteLogic(
    bool bValue
)

Set if this state is allowed to execute its logic.


function CanExecuteLogic

inline bool CanExecuteLogic() const

If this state is allowed to execute logic.


function CanExecuteGraphProperties

virtual bool CanExecuteGraphProperties(
    uint32 OnEvent,
    const USMStateInstance_Base * ForTemplate
) const override

Check if the state can execute its graph properties.

Reimplemented by: FSMConduit::CanExecuteGraphProperties


function CanEvaluateTransitionsOnTick

bool CanEvaluateTransitionsOnTick() const

If this state is allowed to evaluate its transitions on tick. This can return true even when tick evaluation is false in the event an outgoing transition has just completed from an event.


function SortTransitions

void SortTransitions()

Sort incoming and outgoing transitions by priority.


function SetTransitionToTake

void SetTransitionToTake(
    const FSMTransition * Transition
)

The transition this state will be taking.


function GetTransitionToTake

inline const FSMTransition * GetTransitionToTake() const

If set this is the transition the state will take. Generally only valid when EndState is called and if this state is not an end state.


function SetPreviousActiveState

void SetPreviousActiveState(
    FSMState_Base * InPreviousState
)

Record the previous active state before this one.


function SetPreviousActiveTransition

void SetPreviousActiveTransition(
    FSMTransition * InPreviousTransition
)

Record the previous active transition taken to this state.


function GetPreviousActiveState

inline FSMState_Base * GetPreviousActiveState() const

The last state entered previous to this state.


function GetPreviousActiveTransition

inline FSMTransition * GetPreviousActiveTransition() const

The last transition taken to this state.


function NotifyOfParallelReentry

void NotifyOfParallelReentry(
    bool bValue =true
)

This state is being reentered from a parallel state.


function HasBeenReenteredFromParallelState

inline bool HasBeenReenteredFromParallelState() const

This state has just been entered from a parallel state while already active. May be true only for OnStateBegin.


function IsStateEnding

inline bool IsStateEnding() const

True while the state is ending and graph execution is occurring. Prevents restarting this state when it triggers transitions while ending.


function GetStartTime

inline const FDateTime & GetStartTime() const

UTC time the state started.


function GetEndTime

inline const FDateTime & GetEndTime() const

UTC time the state ended.


function SetStartTime

virtual void SetStartTime(
    const FDateTime & InStartTime
)

Set the local start time.

Reimplemented by: FSMStateMachine::SetStartTime


function SetEndTime

virtual void SetEndTime(
    const FDateTime & InEndTime
)

Set the local end time.

Reimplemented by: FSMStateMachine::SetEndTime


function GetStartCycle

inline double GetStartCycle() const

High resolution timer for when this state started.


function ResetGeneratedValues

virtual void ResetGeneratedValues() override

Reset any values set from state machine generation.

Reimplements: FSMNode_Base::ResetGeneratedValues

Reimplemented by: FSMStateMachine::ResetGeneratedValues


Protected Functions Documentation

function AddOutgoingTransition

void AddOutgoingTransition(
    FSMTransition * Transition
)

function AddIncomingTransition

void AddIncomingTransition(
    FSMTransition * Transition
)

function InitializeTransitions

void InitializeTransitions()

Helpers to call any special transition logic.


function ShutdownTransitions

void ShutdownTransitions()

function NotifyInstanceStateHasStarted

virtual void NotifyInstanceStateHasStarted()

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

Reimplemented by: FSMStateMachine::NotifyInstanceStateHasStarted


function FirePreStartEvents

virtual void FirePreStartEvents()

Fire all instance pre start events.


function FirePostStartEvents

virtual void FirePostStartEvents()

Fire all instance post start events.


Public Attributes Documentation

variable bIsRootNode

uint16 bIsRootNode;

Entry node to state machine.


variable bAlwaysUpdate

uint16 bAlwaysUpdate;

Always call state update at least once before ending.


variable bEvalTransitionsOnStart

uint16 bEvalTransitionsOnStart;

Allows transitions to be evaluated in the same tick as StartState.


variable bDisableTickTransitionEvaluation

uint16 bDisableTickTransitionEvaluation;

Prevents conditional transitions for this state from being evaluated on Tick.


variable bStayActiveOnStateChange

uint16 bStayActiveOnStateChange;

If the state should remain active even after a transition is taken from this state.


variable bAllowParallelReentry

uint16 bAllowParallelReentry;

If this state can be reentered from a parallel state if this state is already active.


variable bCanBeEndState

uint16 bCanBeEndState;

If this state can be considered an end state.


Protected Attributes Documentation

variable bReenteredByParallelState

uint16 bReenteredByParallelState;

True only when already active and entered from a parallel state.


variable bCanExecuteLogic

uint16 bCanExecuteLogic;

If this state machine can execute state logic.


variable bIsStateEnding

uint16 bIsStateEnding;

True while the state is ending and graph execution is occurring. Prevents restarting this state when it triggers transitions while ending.


variable PreviousActiveState

FSMState_Base * PreviousActiveState;

The last active state before this state. Resets on entry.


variable PreviousActiveTransition

FSMTransition * PreviousActiveTransition;

The last active transition before this state. Resets on entry.


variable StartTime

FDateTime StartTime;

UTC time the state started.


variable EndTime

FDateTime EndTime;

UTC time the state ended.


Private Attributes Documentation

variable StartCycle

double StartCycle = 0.f;

variable NextTransition

const FSMTransition * NextTransition;

variable IncomingTransitions

TArray< FSMTransition * > IncomingTransitions;

variable OutgoingTransitions

TArray< FSMTransition * > OutgoingTransitions;

Friends

friend FSMTransition

friend struct FSMTransition(
    FSMTransition 
);