Skip to content

FSMNode_Base

Module: SMSystem

#include <SMNode_Base.h>

Inherited by FSMState_Base, FSMTransition

Description

struct FSMNode_Base;

Base struct for all state machine nodes. The Guid MUST be manually initialized right after construction.

Public Functions

Name
const FSMNode_FunctionHandlers * GetFunctionHandlers() const
virtual void UpdateReadStates()
FSMNode_Base()
virtual ~FSMNode_Base() =default
FSMNode_Base(const FSMNode_Base & Node) =default
virtual void Initialize(UObject * Instance)
virtual void InitializeGraphFunctions()
virtual void Reset()
virtual void OnStartedByInstance(USMInstance * Instance)
virtual void OnStoppedByInstance(USMInstance * Instance)
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 bool IsNodeInstanceClassCompatible(UClass * NewNodeInstanceClass) const
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
virtual UClass * GetDefaultNodeInstanceClass() 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 ExecuteInitializeNodes()
virtual void ExecuteShutdownNodes()
virtual void SetServerTimeInState(float InTime)
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()
virtual void ResetGeneratedValues()
FName GetNodeGuidPropertyName()

Protected Functions

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

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

Protected Attributes

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

Name
class FSMEditorConstructionManager

Public Functions Documentation

function GetFunctionHandlers

inline const FSMNode_FunctionHandlers * GetFunctionHandlers() const

function UpdateReadStates

inline virtual void UpdateReadStates()

Reimplemented by: FSMState_Base::UpdateReadStates, FSMTransition::UpdateReadStates


function FSMNode_Base

FSMNode_Base()

function ~FSMNode_Base

virtual ~FSMNode_Base() =default

function FSMNode_Base

FSMNode_Base(
    const FSMNode_Base & Node
) =default

function Initialize

virtual void Initialize(
    UObject * Instance
)

Initialize specific properties and node instances.

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


function InitializeGraphFunctions

virtual void InitializeGraphFunctions()

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

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


function Reset

virtual void Reset()

Resets persistent data.

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


function OnStartedByInstance

virtual void OnStartedByInstance(
    USMInstance * Instance
)

Called when the blueprint owning this node is started.

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


function OnStoppedByInstance

virtual void OnStoppedByInstance(
    USMInstance * Instance
)

Called when the blueprint owning this node has stopped.

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


function HaveGraphFunctionsInitialized

inline bool HaveGraphFunctionsInitialized() const

If all graph function initialization has taken place once.


function IsInitializedForRun

inline bool IsInitializedForRun() const

If the node is currently initialized for this run.


function GetNodeGuid

const FGuid & GetNodeGuid() const

Unique identifier used in constructing nodes from a graph. May not be unique if this is from a parent graph or a reference.


function GenerateNewNodeGuid

void GenerateNewNodeGuid()

function GetGuid

const FGuid & GetGuid() const

Unique identifier taking into account qualified path. Unique across blueprints if called after Instance initialization.


function CalculatePathGuid

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

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

Reimplemented by: FSMStateMachine::CalculatePathGuid


function GetGuidPath

FString GetGuidPath(
    TMap< FString, int32 > & InOutMappedPaths
) const

Unhashed string format of the guid path. MappedPaths are used to adjust for collisions.


function CalculatePathGuidConst

FGuid CalculatePathGuidConst() const

Calculate the path guid but do not set the guid.


function GenerateNewNodeGuidIfNotSet

void GenerateNewNodeGuidIfNotSet()

Only generate a new guid if the current guid is invalid. This needs to be called on new nodes.


function SetNodeGuid

void SetNodeGuid(
    const FGuid & NewGuid
)

function SetOwnerNodeGuid

void SetOwnerNodeGuid(
    const FGuid & NewGuid
)

The state machine's NodeGuid owning this node.


function GetOwnerNodeGuid

inline const FGuid & GetOwnerNodeGuid() const

Unique identifier to help determine which state machine this node belongs to.


function SetOwnerNode

void SetOwnerNode(
    FSMNode_Base * Owner
)

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


function GetOwnerNode

inline virtual FSMNode_Base * GetOwnerNode() const

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

Reimplemented by: FSMStateMachine::GetOwnerNode


function GetOwningInstance

inline USMInstance * GetOwningInstance() const

The state machine instance owning this node.


function CreateNodeInstance

void CreateNodeInstance()

Create the node instance if a node instance class is set.


function CreateStackInstances

void CreateStackInstances()

function RunConstructionScripts

virtual void RunConstructionScripts()

Reimplemented by: FSMStateMachine::RunConstructionScripts


function SetNodeInstanceClass

void SetNodeInstanceClass(
    UClass * NewNodeInstanceClass
)

Calls CheckNodeInstanceCompatible.


function IsNodeInstanceClassCompatible

virtual bool IsNodeInstanceClassCompatible(
    UClass * NewNodeInstanceClass
) const

Derived nodes should overload and check for the correct type.

Reimplemented by: FSMConduit::IsNodeInstanceClassCompatible, FSMState_Base::IsNodeInstanceClassCompatible, FSMStateMachine::IsNodeInstanceClassCompatible, FSMTransition::IsNodeInstanceClassCompatible


function GetNodeInstance

inline virtual USMNodeInstance * GetNodeInstance() const

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

Reimplemented by: FSMStateMachine::GetNodeInstance


function GetOrCreateNodeInstance

virtual USMNodeInstance * GetOrCreateNodeInstance()

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

Reimplemented by: FSMStateMachine::GetOrCreateNodeInstance


function CanEverCreateNodeInstance

inline virtual bool CanEverCreateNodeInstance() const

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

Reimplemented by: FSMStateMachine::CanEverCreateNodeInstance


function GetStackInstancesConst

inline const TArray< TObjectPtr< USMNodeInstance > > & GetStackInstancesConst() const

Returns the current stack instances.


function GetStackInstances

inline TArray< TObjectPtr< USMNodeInstance > > & GetStackInstances()

function GetNodeInStack

USMNodeInstance * GetNodeInStack(
    int32 Index
) const

Returns a specific state from the stack.


function GetDefaultNodeInstanceClass

inline virtual UClass * GetDefaultNodeInstanceClass() const

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

Reimplemented by: FSMConduit::GetDefaultNodeInstanceClass, FSMState_Base::GetDefaultNodeInstanceClass, FSMStateMachine::GetDefaultNodeInstanceClass, FSMTransition::GetDefaultNodeInstanceClass


function GetNodeInstanceClass

inline UClass * GetNodeInstanceClass() const

The current in use node class.


function IsUsingDefaultNodeClass

inline bool IsUsingDefaultNodeClass() const

Is the default node class assigned.


function AddVariableGraphProperty

void AddVariableGraphProperty(
    const FSMGraphProperty_Base_Runtime & GraphProperty,
    const FGuid & OwningTemplateGuid
)

function SetNodeName

void SetNodeName(
    const FString & Name
)

function GetNodeName

inline const FString & GetNodeName() const

function SetTemplateName

void SetTemplateName(
    const FName & Name
)

function GetTemplateName

FName GetTemplateName(
    USMNodeInstance * InNodeInstance =nullptr
) const

Return the template name used to find a node instance archetype.

Parameters:

InNodeInstance
The current node instance we want the template name for. Can be either the main node instance or a stack instance. When nullptr the main node instance template name is used.

Return: The node template name used to discover node instance archetypes or NAME_None if not found.


function AddStackTemplateName

void AddStackTemplateName(
    const FName & Name,
    UClass * TemplateClass
)

function IsActive

inline virtual bool IsActive() const

If this node is active.


function ExecuteInitializeNodes

virtual void ExecuteInitializeNodes()

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


function ExecuteShutdownNodes

virtual void ExecuteShutdownNodes()

Reimplemented by: FSMConduit::ExecuteShutdownNodes, FSMState::ExecuteShutdownNodes, FSMStateMachine::ExecuteShutdownNodes, FSMTransition::ExecuteShutdownNodes


function SetServerTimeInState

virtual void SetServerTimeInState(
    float InTime
)

Set the time in state as recorded from the server.

Reimplemented by: FSMStateMachine::SetServerTimeInState


function GetServerTimeInState

inline float GetServerTimeInState() const

The time in state as recorded by the server. Kept in the base node as transitions can utilize it.


function CanExecuteGraphProperties

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

Checks if the instance is allowed to execute properties automatically.

Parameters:

OnEvent
GRAPH_PROPERTY_EVAL_[TYPE]
ForTemplate
The specific template to check against.

function TryExecuteGraphProperties

virtual bool TryExecuteGraphProperties(
    uint32 OnEvent
)

Execute desired graph properties for the given event.

Reimplemented by: FSMState::TryExecuteGraphProperties


function ExecuteGraphProperties

void ExecuteGraphProperties(
    USMNodeInstance * ForNodeInstance,
    const FGuid * ForTemplateGuid
)

Evaluates graph properties.

Parameters:

ForNodeInstance
The node instance we are evaluating.
ForTemplateGuid
If specified only graph properties for this template will be executed. If null all properties will be executed.

function GetGraphProperties

inline const TArray< FSMGraphProperty_Base_Runtime * > & GetGraphProperties() const

Retrieve the embedded graph properties.


function GetTemplateGraphProperties

inline const TMap< FGuid, FSMGraphPropertyTemplateOwner > & GetTemplateGraphProperties() const

Retrieve the template variable graph properties.


function TryResetVariables

virtual void TryResetVariables()

See if the user wants variables reset.


function IsDebugActive

inline virtual bool IsDebugActive() const

Reimplemented by: FSMConduit::IsDebugActive, FSMTransition::IsDebugActive


function WasDebugActive

inline virtual bool WasDebugActive() const

Reimplemented by: FSMConduit::WasDebugActive, FSMTransition::WasDebugActive


function EditorShutdown

virtual void EditorShutdown()

Performs a safe reset. It's possible referenced structs have changed in the BP and may not be valid.


function ResetGeneratedValues

virtual void ResetGeneratedValues()

Reset any values set from state machine generation.

Reimplemented by: FSMState_Base::ResetGeneratedValues, FSMStateMachine::ResetGeneratedValues, FSMTransition::ResetGeneratedValues


function GetNodeGuidPropertyName

static inline FName GetNodeGuidPropertyName()

Property name of the NodeGuid.


Protected Functions Documentation

function InitializeFunctionHandlers

virtual void InitializeFunctionHandlers()

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

Reimplemented by: FSMConduit::InitializeFunctionHandlers, FSMState::InitializeFunctionHandlers, FSMStateMachine::InitializeFunctionHandlers, FSMTransition::InitializeFunctionHandlers


function PrepareGraphExecution

virtual void PrepareGraphExecution()

Execute the graph.


function SetActive

virtual void SetActive(
    bool bValue
)

function CreateGraphProperties

void CreateGraphProperties()

function CreateGraphPropertiesForTemplate

void CreateGraphPropertiesForTemplate(
    USMNodeInstance * Template,
    const TMap< FGuid, FSMGraphProperty_Base_Runtime * > & MappedGraphPropertyInstances
)

Public Attributes Documentation

variable bValidateGuids

static bool bValidateGuids;

Check whether compiled guid cache matches run-time guid calculation.


variable TimeInState

float TimeInState;

The current time spent in the state.


variable bIsInEndState

bool bIsInEndState;

State Machine is in end state or the state is an end state.

The main case for this is when a local transition graph uses "Is State Machine in End State" (USMGraphK2Node_StateMachineReadNode_InEndState)

Todo:

This should be moved to transitions only, but the now deprecated USMNodeInstance::IsInEndState() uses this.


variable bHasUpdated

bool bHasUpdated;

State has updated at least once.


variable DuplicateId

int32 DuplicateId;

Special indicator in case this node is a duplicate within the same blueprint. If this isn't 0 then the NodeGuid will have been adjusted.


variable NodePosition

FVector2D NodePosition;

The node position in the graph. Set automatically.


variable bHasInputEvents

uint8 bHasInputEvents;

This node has at least one input event present.


variable bWasActive

bool bWasActive = false;

Debug helper in case a state switches to inactive in one frame.


Protected Attributes Documentation

variable FunctionHandlers

FSMNode_FunctionHandlers * FunctionHandlers;

Contains all function handler pointers. Every child node should implement their own type and instantiate it under InitializeFunctionHandlers. This is used to lower struct memory offset costs during GC.


variable Guid

FGuid Guid;

NodeGuid must always be unique. Do not duplicate the guid in any other node in any blueprint.

This is not the same guid that is used at run-time. At run-time all NodeGuids in a path to a node are hashed to form the PathGuid. This is done to account for multiple references and parent graph calls.

If you need to change the path of a node (such as collapse it to a nested state machine) and you need to maintain the old guid for run-time saves to work, you should use the GuidRedirectMap on the primary state machine instance which accepts PathGuids.


variable OwnerGuid

FGuid OwnerGuid;

The state machine's NodeGuid owning this node.


variable PathGuid

FGuid PathGuid;

Unique identifier calculated from this node's place in an instance. Calculated by taking the MD5 hash of the full path of all owner NodeGuids and this NodeGuid. This is what is returned from GetGuid().

ReadWrite so it can be easily read from custom graph nodes.


variable OwnerNode

FSMNode_Base * OwnerNode;

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


variable NodeName

FString NodeName;

variable TemplateName

FName TemplateName;

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


variable StackTemplateNames

TArray< FName > StackTemplateNames;

The names of stack template archetypes used when constructing the stack.


variable StackNodeInstances

TArray< TObjectPtr< USMNodeInstance > > StackNodeInstances;

The node instances for this stack.


variable NodeStackClasses

TArray< TObjectPtr< UClass > > NodeStackClasses;

All classes used in the node stack. The classes are stored here only to help with dependency loading by the engine, specifically with BP nativization. This isn't very useful otherwise as the archetypes (dynamically added default sub-objects) contain instance information which the class won't have.

Without this there may be runtime errors when trying to access internal resources. An example is setting a custom node icon for a stack node with the primary node not loading a custom icon.

The nativization code generated that fails is: "NodeIcon = CastChecked(CastChecked(UTransitionStackA_C__pf1010915279::StaticClass())->UsedAssets[0], ECastCheckedType::NullAllowed);"

Todo:

Consider removing with UE 5.0 as nativization is deprecated.


variable OwningInstance

TObjectPtr< USMInstance > OwningInstance;

The state machine instance owning this node.


variable NodeInstance

TObjectPtr< USMNodeInstance > NodeInstance;

The node instance for this node if it exists.


variable GraphProperties

TArray< FSMGraphProperty_Base_Runtime * > GraphProperties;

Custom graph structs with special handling. Dynamically loaded on initialization from embedded structs.


variable TemplateVariableGraphProperties

TMap< FGuid, FSMGraphPropertyTemplateOwner > TemplateVariableGraphProperties;

Set by the BP compiler. Template Guid -> GraphProperties. Contains data necessary to evaluate variables which have instanced BP graphs.


variable NodeInstanceClass

TObjectPtr< UClass > NodeInstanceClass;

The class to use to construct the node instance if one exists.


Private Attributes Documentation

variable ServerTimeInState

float ServerTimeInState;

Last recorded active time in state from the server.


variable bHaveGraphFunctionsInitialized

uint8 bHaveGraphFunctionsInitialized;

variable bIsInitializedForRun

uint8 bIsInitializedForRun;

variable bIsActive

uint8 bIsActive;

Friends

friend FSMEditorConstructionManager

friend class FSMEditorConstructionManager(
    FSMEditorConstructionManager 
);