Skip to content

USMStateMachineComponent

Module: SMSystem

#include <SMStateMachineComponent.h>

Inherits from UActorComponent, ISMStateMachineInterface, ISMStateMachineNetworkedInterface

Description

class USMStateMachineComponent;

Actor Component wrapper for a State Machine Instance. Supports Replication. Will default state machine context to the owning actor of this component. Call Start() when ready.

Public Functions

Name
virtual void PostLoad() override
virtual void Serialize(FArchive & Ar) override
virtual void PostEditImport() override
virtual void PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent) override
virtual bool ReplicateSubobjects(UActorChannel * Channel, FOutBunch * Bunch, FReplicationFlags * RepFlags) override
virtual void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const override
virtual void InitializeComponent() override
virtual void BeginPlay() override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction) override
virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override
virtual void Initialize(UObject * Context =nullptr) override
images/classes/SMStateMachineComponent/img/nd_img_Initialize.png
virtual void Start() override
images/classes/SMStateMachineComponent/img/nd_img_Start.png
virtual void Update(float DeltaSeconds) override
images/classes/SMStateMachineComponent/img/nd_img_Update.png
virtual void Stop() override
images/classes/SMStateMachineComponent/img/nd_img_Stop.png
virtual void Restart() override
images/classes/SMStateMachineComponent/img/nd_img_Restart.png
virtual void Shutdown() override
images/classes/SMStateMachineComponent/img/nd_img_Shutdown.png
void InitializeAsync(UObject * Context, const FOnStateMachineComponentInitializedAsync & OnCompletedDelegate =FOnStateMachineComponentInitializedAsync())
void K2_InitializeAsync(UObject * Context, FLatentActionInfo LatentInfo)
images/classes/SMStateMachineComponent/img/nd_img_K2_InitializeAsync.png
bool IsInitialized() const
images/classes/SMStateMachineComponent/img/nd_img_IsInitialized.png
bool IsStateMachineActive() const
images/classes/SMStateMachineComponent/img/nd_img_IsStateMachineActive.png
void CopySettingsFromOtherComponent(USMStateMachineComponent * OtherComponent)
images/classes/SMStateMachineComponent/img/nd_img_CopySettingsFromOtherComponent.png
virtual void ServerInitialize(UObject * Context) override
virtual void ServerStart() override
virtual void ServerStop() override
virtual void ServerShutdown() override
virtual void ServerTakeTransition(const FSMTransitionTransaction & TransitionTransaction) override
virtual void ServerActivateState(const FGuid & StateGuid, bool bActive, bool bSetAllParents, bool bActivateNowLocally) override
virtual void ServerFullSync() override
virtual bool HandleNewChannelOpen(UActorChannel * Channel, FReplicationFlags * RepFlags) override
virtual void HandleChannelClosed(UActorChannel * Channel) override
virtual bool CanExecuteTransitionEnteredLogic() const override
virtual bool HasAuthorityToChangeStates() const override
virtual bool HasAuthorityToChangeStatesLocally() const override
virtual bool HasAuthorityToExecuteLogic() const override
virtual bool HasAuthorityToTick() const override
virtual bool IsConfiguredForNetworking() const override
virtual bool HasAuthority() const override
virtual bool IsSimulatedProxy() const override
virtual void SetCanEverNetworkTick(bool bNewValue) override
bool IsNetworked() const
bool IsLocallyOwned() const
bool IsOwningClient() const
bool IsRemoteRoleOwningClient() const
ENetRole GetRemoteRole() const
bool IsListenServer() const
bool CanTickForEnvironment() const
float GetServerUpdateFrequency() const
float GetClientUpdateFrequency() const
void SetCanInstanceNetworkTick(bool bCanEverTick)
images/classes/SMStateMachineComponent/img/nd_img_SetCanInstanceNetworkTick.png
AActor * GetTopMostParentActor() const
images/classes/SMStateMachineComponent/img/nd_img_GetTopMostParentActor.png
USMInstance * GetInstance() const
images/classes/SMStateMachineComponent/img/nd_img_GetInstance.png
USMInstance * GetTemplateForInstance() const
UObject * GetContextForInitialization() const
images/classes/SMStateMachineComponent/img/nd_img_GetContextForInitialization.png
FString GetInfoString() const
bool IsProcessingRPCs() const

Protected Functions

Name
void Internal_OnInstanceInitializedAsync(USMInstance * Instance)
void Internal_OnReplicatedInstanceInitialized(USMInstance * Instance)
void Internal_OnStateMachineStarted(USMInstance * Instance)
void Internal_OnStateMachineUpdated(USMInstance * Instance, float DeltaSeconds)
void Internal_OnStateMachineStopped(USMInstance * Instance)
void Internal_OnStateMachineShutdown(USMInstance * Instance)
void Internal_OnStateMachineTransitionTaken(USMInstance * Instance, FSMTransitionInfo Transition)
void Internal_OnStateMachineStateChanged(USMInstance * Instance, FSMStateInfo ToState, FSMStateInfo FromState)
void Internal_OnStateMachineStateStarted(USMInstance * Instance, FSMStateInfo State)
virtual void PostInitialize()
void OnPostInitialize()
images/classes/SMStateMachineComponent/img/nd_img_OnPostInitialize.png
void InitInstanceTemplate()
void DestroyInstanceTemplate()
void ImportDeprecatedProperties()
USMInstance * CreateInstance(UObject * Context)
virtual void DoInitialize(UObject * Context)
virtual void DoStart()
FORCEINLINE void DoStart(const FSMTransaction_Base & Transaction)
virtual void DoUpdate(float DeltaTime)
virtual void DoStop()
FORCEINLINE void DoStop(const FSMTransaction_Base & Transaction)
virtual void DoShutdown()
FORCEINLINE void DoShutdown(const FSMTransaction_Base & Transaction)
void DoFullSync(const FSMFullSyncTransaction & FullSyncTransaction)
void DoTakeTransitions(const TArray< FSMTransitionTransaction > & InTransactions, bool bAsServer =false)
void DoActivateStates(const TArray< FSMActivateStateTransaction > & StateTransactions)
virtual void ConfigureInstanceNetworkSettings()
bool IsClientAndShouldSkipMulticastStateChange() const
bool IsClientAndCanLocallyChangeStates() const
bool IsServerAndCanLocallyChangeStates() const
bool ShouldClientQueueTransaction() const
void SetClientAsSynced()
void SetServerAsSynced()
bool HasOwningClientConnected() const
void FindAndSetOwningClientConnection()
bool IsServerAndShouldWaitForOwningClient() const
bool IsServerAndNeedsOwningClientSync() const
bool IsServerAndNeedsToWaitToProcessTransactions() const
bool PrepareFullSyncTransaction(FSMFullSyncTransaction & OutFullSyncTransaction) const
void ClearFullSyncTransactions(TArray< TSharedPtr< FSMTransaction_Base > > & InOutTransactions, bool bIgnoreUserAdded =true)
bool HasAuthorityToExecuteLogicForDomain(ESMNetworkConfigurationType Configuration) const
FORCEINLINE bool ShouldMulticast() const
void Server_PrepareTransitionTransactionsForClients(const TArray< FSMTransitionTransaction > & InTransactions)
void Server_PrepareStateTransactionsForClients(const TArray< FSMActivateStateTransaction > & InTransactions)
void ClientServer_ProcessAllTransactions(TArray< TSharedPtr< FSMTransaction_Base > > & InOutTransactions)
void Client_SendOutgoingTransactions()
bool Client_DoesClientNeedToSendInitialSync() const
bool Client_SendInitialSync()
void SERVER_Initialize(const FSMInitializeTransaction & Transaction)
Server.
void SERVER_Start(const FSMTransaction_Base & Transaction)
void SERVER_Update(float DeltaTime)
void SERVER_Stop(const FSMTransaction_Base & Transaction)
void SERVER_Shutdown(const FSMTransaction_Base & Transaction)
void SERVER_TakeTransitions(const TArray< FSMTransitionTransaction > & TransitionTransactions)
void SERVER_ActivateStates(const TArray< FSMActivateStateTransaction > & StateTransactions)
void SERVER_RequestFullSync(bool bForceFullRefresh =false)
void SERVER_FullSync(const FSMFullSyncTransaction & FullSyncTransaction)
virtual void REP_OnInstanceLoaded()
template \<typename T >
void
QueueOutgoingTransactions(const TArray< T > & InTransactions)
template \<typename T >
void
QueueOutgoingTransactions(const T & InTransaction)
template \<typename T >
bool
QueueClientPendingTransactions(const TArray< T > & InTransactions)
template \<typename T >
bool
QueueClientPendingTransactions(const T & InTransaction)

Public Attributes

Name
FOnStateMachineInitializedSignature OnStateMachineInitializedEvent
FOnStateMachineStartedSignature OnStateMachineStartedEvent
FOnStateMachineUpdatedSignature OnStateMachineUpdatedEvent
FOnStateMachineStoppedSignature OnStateMachineStoppedEvent
FOnStateMachineShutdownSignature OnStateMachineShutdownEvent
FOnStateMachineTransitionTakenSignature OnStateMachineTransitionTakenEvent
FOnStateMachineStateChangedSignature OnStateMachineStateChangedEvent
FOnStateMachineStateStartedSignature OnStateMachineStateStartedEvent
uint32 bAutomaticallyHandleNewConnections
TSubclassOf< USMInstance > StateMachineClass
End Server.
uint8 bInitializeOnBeginPlay
uint8 bStartOnBeginPlay
uint8 bStopOnEndPlay
ESMThreadMode BeginPlayInitializationMode
uint8 bReuseInstanceAfterShutdown
uint8 bLetInstanceManageTick
TEnumAsByte< ESMNetworkConfigurationType > StateChangeAuthority
TEnumAsByte< ESMNetworkConfigurationType > NetworkTransitionConfiguration
TEnumAsByte< ESMNetworkConfigurationType > NetworkTickConfiguration
TEnumAsByte< ESMNetworkConfigurationType > NetworkStateExecution
TEnumAsByte< ESMNetworkConfigurationType > NetworkStateConfiguration
uint8 bIncludeSimulatedProxies
ESMThreadMode ReplicatedInitializationMode
TEnumAsByte< ESMNetworkConfigurationType > NetworkTransitionEnteredConfiguration
uint8 bWaitForTransactionsFromServer
uint8 bTakeTransitionsFromServerOnly
uint8 bHandleControllerChange
uint8 bCalculateServerTimeForClients
uint8 bUseOwnerNetUpdateFrequency
float ServerNetUpdateFrequency
float ClientNetUpdateFrequency
uint8 bAlwaysMulticast

Protected Attributes

Name
TObjectPtr< USMInstance > R_Instance
TObjectPtr< USMInstance > InstanceTemplate
uint8 bCanInstanceNetworkTick
uint8 bInitialized
uint8 bOverrideTick_DEPRECATED
uint8 bCanEverTick_DEPRECATED
uint8 bOverrideTickInterval_DEPRECATED
float TickInterval_DEPRECATED

Friends

Name
struct FInitiateServerCall(FInitiateServerCall )
struct FQueuedTransactionHelper(FQueuedTransactionHelper )

Public Functions Documentation

function PostLoad

virtual void PostLoad() override

function Serialize

virtual void Serialize(
    FArchive & Ar
) override

function PostEditImport

virtual void PostEditImport() override

function PostEditChangeProperty

virtual void PostEditChangeProperty(
    FPropertyChangedEvent & PropertyChangedEvent
) override

function ReplicateSubobjects

virtual bool ReplicateSubobjects(
    UActorChannel * Channel,
    FOutBunch * Bunch,
    FReplicationFlags * RepFlags
) override

function GetLifetimeReplicatedProps

virtual void GetLifetimeReplicatedProps(
    TArray< FLifetimeProperty > & OutLifetimeProps
) const override

function InitializeComponent

virtual void InitializeComponent() override

function BeginPlay

virtual void BeginPlay() override

function EndPlay

virtual void EndPlay(
    const EEndPlayReason::Type EndPlayReason
) override

function TickComponent

virtual void TickComponent(
    float DeltaTime,
    ELevelTick TickType,
    FActorComponentTickFunction * ThisTickFunction
) override

function OnComponentDestroyed

virtual void OnComponentDestroyed(
    bool bDestroyingHierarchy
) override

function Initialize

virtual void Initialize(
    UObject * Context =nullptr
) override

images/classes/SMStateMachineComponent/img/nd_img_Initialize.png

Prepare the state machine for use.

This cannot occur during automatic Component Activation when working with Listen servers and playing in the editor. The game will incorrectly report as Stand Alone.

Parameters:

Context
The context to use for the state machine. A null context will imply the owner of the component should be used.

function Start

virtual void Start() override

images/classes/SMStateMachineComponent/img/nd_img_Start.png

Start the root state machine.


function Update

virtual void Update(
    float DeltaSeconds
) override

images/classes/SMStateMachineComponent/img/nd_img_Update.png

Manual way of updating the root state machine if tick is disabled. Not used by default and for custom update implementations. This will either call update locally if not replicated or call update on the server. For more control in a network environment calling Update from GetInstance() may be more appropriate.


function Stop

virtual void Stop() override

images/classes/SMStateMachineComponent/img/nd_img_Stop.png

This will complete the state machine's current state and force the machine to end regardless of if the state is an end state.


function Restart

virtual void Restart() override

images/classes/SMStateMachineComponent/img/nd_img_Restart.png

Forcibly restart the state machine and place it back into an entry state.


function Shutdown

virtual void Shutdown() override

images/classes/SMStateMachineComponent/img/nd_img_Shutdown.png

Shutdown this instance. Calls Stop. Must call initialize again before use. If the goal is to restart the state machine later call Stop instead.


function InitializeAsync

void InitializeAsync(
    UObject * Context,
    const FOnStateMachineComponentInitializedAsync & OnCompletedDelegate =FOnStateMachineComponentInitializedAsync()
)

Prepare the state machine for use on a separate thread.

Parameters:

Context
The context to use for the state machine. A null context will imply the owner of the component should be used.

function K2_InitializeAsync

void K2_InitializeAsync(
    UObject * Context,
    FLatentActionInfo LatentInfo
)

images/classes/SMStateMachineComponent/img/nd_img_K2_InitializeAsync.png

Prepare the state machine for use on a separate thread.


function IsInitialized

inline bool IsInitialized() const

images/classes/SMStateMachineComponent/img/nd_img_IsInitialized.png

If the state machine component has fully initialized.


function IsStateMachineActive

bool IsStateMachineActive() const

images/classes/SMStateMachineComponent/img/nd_img_IsStateMachineActive.png

Checks if the instance is initialized and active.


function CopySettingsFromOtherComponent

void CopySettingsFromOtherComponent(
    USMStateMachineComponent * OtherComponent
)

images/classes/SMStateMachineComponent/img/nd_img_CopySettingsFromOtherComponent.png

Sets relevant settings from another state machine component, ideally used with or immediately after component creation. Does not copy state machine instance data.

Parameters:

OtherComponent
A state machine component for settings to be copied from. Accepts null.

function ServerInitialize

virtual void ServerInitialize(
    UObject * Context
) override

Signal to the server to initialize. Can be called by either the server or owning client that has state change authority. Only the server will perform initialization directly from this call. The client will always initialize post instance replication.


function ServerStart

virtual void ServerStart() override

Signal to the server to start processing. Can be called by either the server or owning client that has state change authority.


function ServerStop

virtual void ServerStop() override

Signal to the server to stop processing. Can be called by either the server or owning client that has state change authority.


function ServerShutdown

virtual void ServerShutdown() override

Signal to the server to shutdown. Can be called by either the server or owning client that has state change authority.


function ServerTakeTransition

virtual void ServerTakeTransition(
    const FSMTransitionTransaction & TransitionTransaction
) override

Provide a transition for the server to take.


function ServerActivateState

virtual void ServerActivateState(
    const FGuid & StateGuid,
    bool bActive,
    bool bSetAllParents,
    bool bActivateNowLocally
) override

Signal to the server to activate a specific state. Can be called by either the server or owning client that has state change authority.

Parameters:

StateGuid
The guid of the specific state to activate.
bActive
Add or remove the state from the owning state machine's active states.
bSetAllParents
Sets the active state of all super state machines. A parent state machine won't be deactivated unless there are no other states active.
bActivateNowLocally
If the state is becoming active and this component has authority to activate locally it will run OnStateBegin this tick.

function ServerFullSync

virtual void ServerFullSync() override

Notify the server to update all clients with its current states.


function HandleNewChannelOpen

virtual bool HandleNewChannelOpen(
    UActorChannel * Channel,
    FReplicationFlags * RepFlags
) override

Handle when a new connection is added, ensuring the connection receives the initial transaction if required. This is called automatically when using bAutomaticallyHandleNewConnections.

Requires the component registered, active, initialized.

Parameters:

Channel
The newly added actor channel.
RepFlags
The replication flags for the channel.

Return: If the channel was added.


function HandleChannelClosed

virtual void HandleChannelClosed(
    UActorChannel * Channel
) override

Handle when a channel is closed. Called automatically with bAutomaticallyHandleNewConnections. Default behavior just removes the channel and all null channels from the set.

Parameters:

Channel
The channel to be removed. If null the connection set is cleaned of null channels.

function CanExecuteTransitionEnteredLogic

virtual bool CanExecuteTransitionEnteredLogic() const override

If transition enter logic can currently execute.


function HasAuthorityToChangeStates

virtual bool HasAuthorityToChangeStates() const override

If this connection has the authority to change states.


function HasAuthorityToChangeStatesLocally

virtual bool HasAuthorityToChangeStatesLocally() const override

If the caller is both allowed to change states and can do so without server supervision.


function HasAuthorityToExecuteLogic

virtual bool HasAuthorityToExecuteLogic() const override

If this connection has the authority to execute logic.


function HasAuthorityToTick

virtual bool HasAuthorityToTick() const override

If this connection has authority to tick. Even if it does, ticking may be disabled by the user.


function IsConfiguredForNetworking

virtual bool IsConfiguredForNetworking() const override

Checks if this component is networked and replicated.


function HasAuthority

virtual bool HasAuthority() const override

If the this instance has authority (Such as an instance running on a server)


function IsSimulatedProxy

virtual bool IsSimulatedProxy() const override

If this is only a simulated instance.


function SetCanEverNetworkTick

virtual void SetCanEverNetworkTick(
    bool bNewValue
) override

Sets bCanInstanceNetworkTick directly. Requires tick authority.


function IsNetworked

bool IsNetworked() const

If this is a networked environment.


function IsLocallyOwned

bool IsLocallyOwned() const

If this belongs to a player controlled on this client.


function IsOwningClient

bool IsOwningClient() const

If this is the client that owns this component.


function IsRemoteRoleOwningClient

bool IsRemoteRoleOwningClient() const

If this is the authority for an owning client.


function GetRemoteRole

ENetRole GetRemoteRole() const

Return the remote role of the owner.


function IsListenServer

bool IsListenServer() const

If this is the listen server.


function CanTickForEnvironment

bool CanTickForEnvironment() const

Checks tick settings depending on if this is a networked environment or not.


function GetServerUpdateFrequency

float GetServerUpdateFrequency() const

Retrieve the correct update frequency to use.


function GetClientUpdateFrequency

float GetClientUpdateFrequency() const

Retrieve the correct update frequency to use.


function SetCanInstanceNetworkTick

void SetCanInstanceNetworkTick(
    bool bCanEverTick
)

images/classes/SMStateMachineComponent/img/nd_img_SetCanInstanceNetworkTick.png

Special override to change instance tick settings when networked. Requires tick authority to make any changes. Calling USMInstance::SetCanEverTick() on the primary instance will update the network tick, which may make this call unnecessary.

This call will likely be deprecated in the future and replaced with SetCanEverNetworkTick().


function GetTopMostParentActor

AActor * GetTopMostParentActor() const

images/classes/SMStateMachineComponent/img/nd_img_GetTopMostParentActor.png

Find the highest level owning actor of this component. Useful if this component is used within a child actor component.


function GetInstance

inline USMInstance * GetInstance() const

images/classes/SMStateMachineComponent/img/nd_img_GetInstance.png

Retrieve the real state machine instance this component wraps.


function GetTemplateForInstance

inline USMInstance * GetTemplateForInstance() const

Retrieve the archetype template the state machine instance is based on. Only valid for the CDO.


function GetContextForInitialization

UObject * GetContextForInitialization() const

images/classes/SMStateMachineComponent/img/nd_img_GetContextForInitialization.png

The context to use for initialization. Defaults to GetOwner(). For native implementations overload GetContextForInitialization_Implementation.

Return: The context to use when initializing the state machine instance.


function GetInfoString

FString GetInfoString() const

Create a string containing relevant information about this component.


function IsProcessingRPCs

inline bool IsProcessingRPCs() const

True while ClientServer_ProcessAllTransactions is processing.


Protected Functions Documentation

function Internal_OnInstanceInitializedAsync

void Internal_OnInstanceInitializedAsync(
    USMInstance * Instance
)

Callback from when the instance initializes, used for async initialization.


function Internal_OnReplicatedInstanceInitialized

void Internal_OnReplicatedInstanceInitialized(
    USMInstance * Instance
)

When the instance has initialized from replication.


function Internal_OnStateMachineStarted

void Internal_OnStateMachineStarted(
    USMInstance * Instance
)

function Internal_OnStateMachineUpdated

void Internal_OnStateMachineUpdated(
    USMInstance * Instance,
    float DeltaSeconds
)

function Internal_OnStateMachineStopped

void Internal_OnStateMachineStopped(
    USMInstance * Instance
)

function Internal_OnStateMachineShutdown

void Internal_OnStateMachineShutdown(
    USMInstance * Instance
)

function Internal_OnStateMachineTransitionTaken

void Internal_OnStateMachineTransitionTaken(
    USMInstance * Instance,
    FSMTransitionInfo Transition
)

function Internal_OnStateMachineStateChanged

void Internal_OnStateMachineStateChanged(
    USMInstance * Instance,
    FSMStateInfo ToState,
    FSMStateInfo FromState
)

function Internal_OnStateMachineStateStarted

void Internal_OnStateMachineStateStarted(
    USMInstance * Instance,
    FSMStateInfo State
)

function PostInitialize

virtual void PostInitialize()

Called after the state machine has initialized either locally or by replication.


function OnPostInitialize

void OnPostInitialize()

images/classes/SMStateMachineComponent/img/nd_img_OnPostInitialize.png

Called after the state machine has initialized either locally or by replication.


function InitInstanceTemplate

void InitInstanceTemplate()

Initialize the USMInstance template based on the current StateMachineClass.


function DestroyInstanceTemplate

void DestroyInstanceTemplate()

Remove the current USMInstance template.


function ImportDeprecatedProperties

void ImportDeprecatedProperties()

Tick overrides are deprecated in favor of modifying the USMInstance template.


function CreateInstance

USMInstance * CreateInstance(
    UObject * Context
)

function DoInitialize

virtual void DoInitialize(
    UObject * Context
)

function DoStart

virtual void DoStart()

function DoStart

inline FORCEINLINE void DoStart(
    const FSMTransaction_Base & Transaction
)

function DoUpdate

virtual void DoUpdate(
    float DeltaTime
)

function DoStop

virtual void DoStop()

function DoStop

inline FORCEINLINE void DoStop(
    const FSMTransaction_Base & Transaction
)

function DoShutdown

virtual void DoShutdown()

function DoShutdown

inline FORCEINLINE void DoShutdown(
    const FSMTransaction_Base & Transaction
)

function DoFullSync

void DoFullSync(
    const FSMFullSyncTransaction & FullSyncTransaction
)

Sync all states locally.


function DoTakeTransitions

void DoTakeTransitions(
    const TArray< FSMTransitionTransaction > & InTransactions,
    bool bAsServer =false
)

Perform local processing of transactions.


function DoActivateStates

void DoActivateStates(
    const TArray< FSMActivateStateTransaction > & StateTransactions
)

Perform local processing of transactions.


function ConfigureInstanceNetworkSettings

virtual void ConfigureInstanceNetworkSettings()

Configure instance specific network properties.


function IsClientAndShouldSkipMulticastStateChange

bool IsClientAndShouldSkipMulticastStateChange() const

Checks if this instance can skip server authored state changes.


function IsClientAndCanLocallyChangeStates

bool IsClientAndCanLocallyChangeStates() const

If the caller is the client and can process AND change states.


function IsServerAndCanLocallyChangeStates

bool IsServerAndCanLocallyChangeStates() const

If the caller is the server and can change states.


function ShouldClientQueueTransaction

bool ShouldClientQueueTransaction() const

Determine if transactions should be queued by the local client.


function SetClientAsSynced

void SetClientAsSynced()

Resets pending transactions and sync requests.


function SetServerAsSynced

void SetServerAsSynced()

Sets the server as being up to date with the client.


function HasOwningClientConnected

bool HasOwningClientConnected() const

Checks if the owning client has connected to the server.


function FindAndSetOwningClientConnection

void FindAndSetOwningClientConnection()

Checks if the owning client has already connected and sets the internal flag.


function IsServerAndShouldWaitForOwningClient

bool IsServerAndShouldWaitForOwningClient() const

If this instance should be waiting for the owning client to connect.


function IsServerAndNeedsOwningClientSync

bool IsServerAndNeedsOwningClientSync() const

If this instance should be waiting for the owning client to connect and provide its initial sync.


function IsServerAndNeedsToWaitToProcessTransactions

bool IsServerAndNeedsToWaitToProcessTransactions() const

Checks if the server should be waiting before processing transactions. This does not check frequency.


function PrepareFullSyncTransaction

bool PrepareFullSyncTransaction(
    FSMFullSyncTransaction & OutFullSyncTransaction
) const

Create a full sync transaction from this instance.


function ClearFullSyncTransactions

void ClearFullSyncTransactions(
    TArray< TSharedPtr< FSMTransaction_Base > > & InOutTransactions,
    bool bIgnoreUserAdded =true
)

Clears all transactions matching the type from the input array.

Parameters:

InOutTransactions
Transactions to search and modify.
bIgnoreUserAdded
Do not clear full sync transactions triggered from user loading states.

function HasAuthorityToExecuteLogicForDomain

bool HasAuthorityToExecuteLogicForDomain(
    ESMNetworkConfigurationType Configuration
) const

Check for logic execution authority against specific domain.


function ShouldMulticast

inline FORCEINLINE bool ShouldMulticast() const

If multicast should be used, otherwise client calls will be used.


function Server_PrepareTransitionTransactionsForClients

void Server_PrepareTransitionTransactionsForClients(
    const TArray< FSMTransitionTransaction > & InTransactions
)

Update transaction array to be replicated to clients.


function Server_PrepareStateTransactionsForClients

void Server_PrepareStateTransactionsForClients(
    const TArray< FSMActivateStateTransaction > & InTransactions
)

Update transaction array to be replicated to clients.


function ClientServer_ProcessAllTransactions

void ClientServer_ProcessAllTransactions(
    TArray< TSharedPtr< FSMTransaction_Base > > & InOutTransactions
)

Server: Iterate through the outgoing queue sending all transactions to the correct proxies. Client: Iterate through the pending queue running on methods locally. The client will be assumed to be in sync after.

Parameters:

InOutTransactions
Transactions in will be processed and the array cleared.

function Client_SendOutgoingTransactions

void Client_SendOutgoingTransactions()

Special handling when the client is executing queued transactions the server should execute.


function Client_DoesClientNeedToSendInitialSync

bool Client_DoesClientNeedToSendInitialSync() const

If the owning client is responsible for sending the initial sync.


function Client_SendInitialSync

bool Client_SendInitialSync()

Call from the owning client that is state change authoritative. Return false if failed.


function SERVER_Initialize

void SERVER_Initialize(
    const FSMInitializeTransaction & Transaction
)

Server.

Signal the server to initialize state machine.


function SERVER_Start

void SERVER_Start(
    const FSMTransaction_Base & Transaction
)

Signal the server to start the state machine.


function SERVER_Update

void SERVER_Update(
    float DeltaTime
)

Update the server state machine.


function SERVER_Stop

void SERVER_Stop(
    const FSMTransaction_Base & Transaction
)

Signal the server to end the state machine.


function SERVER_Shutdown

void SERVER_Shutdown(
    const FSMTransaction_Base & Transaction
)

Signal the server to shutdown the state machine.


function SERVER_TakeTransitions

void SERVER_TakeTransitions(
    const TArray< FSMTransitionTransaction > & TransitionTransactions
)

Signal the server of transition transactions.


function SERVER_ActivateStates

void SERVER_ActivateStates(
    const TArray< FSMActivateStateTransaction > & StateTransactions
)

Signal the server to activate a specific state.


function SERVER_RequestFullSync

void SERVER_RequestFullSync(
    bool bForceFullRefresh =false
)

Signal the server that it should force all clients to sync.

Parameters:

bForceFullRefresh
Signal that the refresh should always be accepted and the local network settings should be refreshed.

function SERVER_FullSync

void SERVER_FullSync(
    const FSMFullSyncTransaction & FullSyncTransaction
)

Signal to the server that it should accept the current state of the owning client.


function REP_OnInstanceLoaded

virtual void REP_OnInstanceLoaded()

When the StateMachineInstance is loaded from the server.


function QueueOutgoingTransactions

template <typename T >
inline void QueueOutgoingTransactions(
    const TArray< T > & InTransactions
)

function QueueOutgoingTransactions

template <typename T >
inline void QueueOutgoingTransactions(
    const T & InTransaction
)

function QueueClientPendingTransactions

template <typename T >
inline bool QueueClientPendingTransactions(
    const TArray< T > & InTransactions
)

function QueueClientPendingTransactions

template <typename T >
inline bool QueueClientPendingTransactions(
    const T & InTransaction
)

Public Attributes Documentation

variable OnStateMachineInitializedEvent

FOnStateMachineInitializedSignature OnStateMachineInitializedEvent;

Called when the state machine is first initialized.


variable OnStateMachineStartedEvent

FOnStateMachineStartedSignature OnStateMachineStartedEvent;

Called right before the state machine is started.


variable OnStateMachineUpdatedEvent

FOnStateMachineUpdatedSignature OnStateMachineUpdatedEvent;

Called right before the state machine is updated.


variable OnStateMachineStoppedEvent

FOnStateMachineStoppedSignature OnStateMachineStoppedEvent;

Called right after the state machine has ended.


variable OnStateMachineShutdownEvent

FOnStateMachineShutdownSignature OnStateMachineShutdownEvent;

Called right after the state machine has shutdown.


variable OnStateMachineTransitionTakenEvent

FOnStateMachineTransitionTakenSignature OnStateMachineTransitionTakenEvent;

Called when a transition has evaluated to true and is being taken.


variable OnStateMachineStateChangedEvent

FOnStateMachineStateChangedSignature OnStateMachineStateChangedEvent;

Called when a state machine has switched states.


variable OnStateMachineStateStartedEvent

FOnStateMachineStateStartedSignature OnStateMachineStateStartedEvent;

Called when a state has started. This happens after OnStateMachineStateChanged and all previous transitions have evaluated.


variable bAutomaticallyHandleNewConnections

uint32 bAutomaticallyHandleNewConnections;

New connections generally need to receive an initial sync transaction or they will not function. This is performed automatically by default.

When true, new connections are automatically determined through ReplicateSubObjects(). When false, you must manually call HandleNewChannelOpen() and HandleChannelClosed().


variable StateMachineClass

TSubclassOf< USMInstance > StateMachineClass;

End Server.

The state machine class to use for this instance.


variable bInitializeOnBeginPlay

uint8 bInitializeOnBeginPlay;

Automatically initialize the state machine when the component begins play. This will set the Context to the owning actor of this component. This happens in two stages: On InitializeComponent the state machine is instantiated, on BeginPlay the state machine is initialized.


variable bStartOnBeginPlay

uint8 bStartOnBeginPlay;

Automatically start the state machine when the component begins play.


variable bStopOnEndPlay

uint8 bStopOnEndPlay;

Automatically stop the state machine when the component ends play.


variable BeginPlayInitializationMode

ESMThreadMode BeginPlayInitializationMode;

Configure multi-threaded options to use with InitializeOnBeginPlay. Running async can reduce blocking operations on the game thread but increase total initialization time per component.


variable bReuseInstanceAfterShutdown

uint8 bReuseInstanceAfterShutdown;

If set to false when shutdown is called the internal reference to the state machine instance is cleared so it can be garbage collected. If set to true the instance will not be freed and will be re-used when initializing.

When used with replication and re-initializing the component, this setting may be better set to false so the instance can run its first time OnRep initialize logic.


variable bLetInstanceManageTick

uint8 bLetInstanceManageTick;

The default behavior is to let the actor component tick the state machine when it ticks. This legacy option allows the instance to register as a tickable object instead.

Deprecated:

This property is deprecated and will no longer be supported in future versions. Remove uses of this property and configure the component to manage tick.


variable StateChangeAuthority

TEnumAsByte< ESMNetworkConfigurationType > StateChangeAuthority;

The authoritative domain to determine the state of the state machine. This impacts evaluating transitions, activating states, start, and stop. Requires Replication and a networked environment.

Client - The client is allowed to evaluate and send state changes to the server. The server will only process and broadcast changes from the client. Server - Only the server will determine state changes which it will then send to the client. ClientAndServer - This is unsupported and is completely up to your implementation to determine which state the state machine is in for all connections.

Warning:

Client authority on an actor without a player controller will not work. Remote calls to a server can only be made with a player controller.


variable NetworkTransitionConfiguration

TEnumAsByte< ESMNetworkConfigurationType > NetworkTransitionConfiguration;

Deprecated:

Use StateChangeAuthority instead.


variable NetworkTickConfiguration

TEnumAsByte< ESMNetworkConfigurationType > NetworkTickConfiguration;

Determine which domain to tick. The state machine must allow ticking for this to take effect.


variable NetworkStateExecution

TEnumAsByte< ESMNetworkConfigurationType > NetworkStateExecution;

The domain which primary state logic can be executed on. Requires Replication and a networked environment. Client - Only the client will execute state logic. Server - Only the server will execute state logic. ClientAndServer - Both the server and client will execute state logic.

This impacts OnStateBegin, OnStateUpdate, and OnStateEnd. All other optional execution nodes will always execute across all domains.


variable NetworkStateConfiguration

TEnumAsByte< ESMNetworkConfigurationType > NetworkStateConfiguration;

Deprecated:

Use NetworkStateExecution instead.


variable bIncludeSimulatedProxies

uint8 bIncludeSimulatedProxies;

Include simulated proxies when broadcasting changes and executing client logic. The default behavior only includes autonomous proxies such as actors possessed by a player controller. Client driven transitions will not work without a player controller.


variable ReplicatedInitializationMode

ESMThreadMode ReplicatedInitializationMode;

Configure multi-threaded options to use when the instance is replicated to proxies. Running async can reduce blocking operations on the game thread but increase total initialization time per component.


variable NetworkTransitionEnteredConfiguration

TEnumAsByte< ESMNetworkConfigurationType > NetworkTransitionEnteredConfiguration;

The domain to execute OnTransitionEntered logic. This fires for transitions when one is being taken to the next state.

This setting respects bIncludeSimulatedProxies.


variable bWaitForTransactionsFromServer

uint8 bWaitForTransactionsFromServer;

When true, if the client initiates a change it will only notify the server and not make the change until the server updates the client. When false, the client will make the change immediately.

This is generally not needed unless you want to retrieve the time the server spent in a state during OnStateEnd.


variable bTakeTransitionsFromServerOnly

uint8 bTakeTransitionsFromServerOnly;

Deprecated:

Use bWaitForTransactionsFromServer instead.


variable bHandleControllerChange

uint8 bHandleControllerChange;

Attempt to automatically handle when the owning pawn is possessed or unpossessed by a player controller. This will force a full refresh using the current server states and update all connected clients' network settings.

This works best when the authority is set to server.

This may not work correctly when set to a client authority and going to or from a simulated proxy. It is not possible to have a client driven state machine owned by the server. In this case you may want to disable this option and handle OnPossess and OnUnPossess of the pawn, manually shutting down and initializing the state machine as desired.


variable bCalculateServerTimeForClients

uint8 bCalculateServerTimeForClients;

Calculate the server time spent in states when NetworkTickConfiguration is set to client only. This only impacts the client value of USMStateInstance_Base::GetServerTimeInState() and has no effect if the server is ticking.

When true and the server is not ticking, it will take a measurement from the timestamp of when the state first started compared to when the server received the request to end the state.

If only using auto-bound events, or the state machine is being manually updated, this may not be necessary and disabling could increase accuracy.


variable bUseOwnerNetUpdateFrequency

uint8 bUseOwnerNetUpdateFrequency;

Uses the NetUpdateFrequency of the component owner.


variable ServerNetUpdateFrequency

float ServerNetUpdateFrequency;

The update rate (per second) to use for server RPC processing.

A lower frequency means less remote calls but larger average payload size. Total bandwidth over time may be less due to better transaction packing. A higher frequency means more frequent remote calls but smaller average payload size. Total bandwidth used may be more over time.


variable ClientNetUpdateFrequency

float ClientNetUpdateFrequency;

The update rate (per second) for the client to use if it is performing RPC processing.

A lower frequency means less remote calls but larger average payload size. Total bandwidth over time may be less due to better transaction packing. A higher frequency means more frequent remote calls but smaller average payload size. Total bandwidth used may be more over time.


variable bAlwaysMulticast

uint8 bAlwaysMulticast;

Configure whether the server should always use mutlicast RPCs regardless of what bIncludeSimulatedProxies is set to. This can support the case where the state machine needs to be replicated to simulated proxies, but the proxies should not execute state logic.


Protected Attributes Documentation

variable R_Instance

TObjectPtr< USMInstance > R_Instance;

The actual state machine instance.


variable InstanceTemplate

TObjectPtr< USMInstance > InstanceTemplate;

The template to use when initializing the state machine. Only valid within the CDO.


variable bCanInstanceNetworkTick

uint8 bCanInstanceNetworkTick;

Set from the template and adjusted for the network configuration.


variable bInitialized

uint8 bInitialized;

If the component is initialized.


variable bOverrideTick_DEPRECATED

uint8 bOverrideTick_DEPRECATED;

If false the default setting will be used. When replicated this component may still perform some level of override depending on the NetworkTickConfiguration.

Deprecated:

Use bCanEverTick on the instance template instead.


variable bCanEverTick_DEPRECATED

uint8 bCanEverTick_DEPRECATED;

Allow the machine to tick. Overrides default State Machine blueprint configuration.

Deprecated:

Use bCanEverTick on the instance template instead.


variable bOverrideTickInterval_DEPRECATED

uint8 bOverrideTickInterval_DEPRECATED;

If false the default setting will be used.

Deprecated:

Use TickInterval on the instance template instead.


variable TickInterval_DEPRECATED

float TickInterval_DEPRECATED;

Time in seconds between native ticks. This mostly affects the "Update" rate of the state machine. Overloaded Ticks won't be affected. Overrides default state machine blueprint configuration.

Deprecated:

Use TickInterval on the instance template instead.


Private Attributes Documentation

variable CurrentActorChannels

TSet< TObjectPtr< UActorChannel > > CurrentActorChannels;

variable OutgoingTransactions

TArray< TSharedPtr< FSMTransaction_Base > > OutgoingTransactions;

Transactions the server is preparing to send.


variable PendingTransactions

TArray< TSharedPtr< FSMTransaction_Base > > PendingTransactions;

Transactions which could not be processed yet.


variable LastNetUpdateTime

float LastNetUpdateTime = 0.f;

Time spent since last update.


variable NetworkRole

ENetRole NetworkRole;

variable RemoteRole

ENetRole RemoteRole;

variable bProcessingRPCs

uint32 bProcessingRPCs;

True during RPC processing.


variable bJustExecutedRPCLocally

uint32 bJustExecutedRPCLocally;

If the server should skip transaction processing for this frame in scope.


variable bServerJustPreparedRPC

uint32 bServerJustPreparedRPC;

If the server is originating an RPC transaction for a frame in scope.


variable bClientJustPreparedRPC

uint32 bClientJustPreparedRPC;

If the client is originating an RPC transaction for a frame in scope.


variable bWaitingForServerSync

uint32 bWaitingForServerSync;

If this is a client that needs replicated states from the server.


variable bClientInSync

uint32 bClientInSync;

The client is estimated to be in sync with the server.


variable bServerInSync

uint32 bServerInSync;

The server is estimated to be in sync with the client.


variable bProxiesWaitingForOwningSync

uint32 bProxiesWaitingForOwningSync;

At least one proxy requires a sync, but the server needs initial data from the owning client.


variable bClientHasPendingFullSyncTransaction

uint32 bClientHasPendingFullSyncTransaction;

If the client has queued a full sync transaction.


variable bQueueClientTransactions

uint32 bQueueClientTransactions;

The client is queuing transactions.


variable bClientSendingOutgoingTransactions

uint32 bClientSendingOutgoingTransactions;

When the client is sending its outgoing transactions.


variable bOwningClientConnected

uint32 bOwningClientConnected;

If the owning client has connected to the server.


variable bCalledShutdownWhileWaitingForOwningClient

uint32 bCalledShutdownWhileWaitingForOwningClient;

User called shutdown before the owning connected and the server was waiting.


variable bPerformInitialSyncBeforeQueue

uint32 bPerformInitialSyncBeforeQueue;

Perform an initial (empty) full sync and then execute the remaining queue.


variable bClientNeedsToSendInitialSync

uint32 bClientNeedsToSendInitialSync;

True only if auth client still needs to send an initial sync to the server.


variable bNonAuthServerHasInitialStates

uint32 bNonAuthServerHasInitialStates;

Special flag if a non-auth server was started with custom loaded states. This will tell the server to ignore the initial sync from the auth client.


variable bHasServerRemoteRoleJustChanged

uint32 bHasServerRemoteRoleJustChanged;

If the server has had its remote role suddenly changed.


variable ComponentToCopy

TObjectPtr< USMStateMachineComponent > ComponentToCopy;

Provide an existing component to copy certain settings from during dynamic component creation. This is only read during initialize component. Does not copy state machine instance data. Setting this will override all other settings when called through the blueprint node Add State Machine Component.


variable bWaitingForInitialize

uint8 bWaitingForInitialize;

variable bWaitingForStartOnBeginPlay

uint8 bWaitingForStartOnBeginPlay;

variable bInitializeAsync

uint8 bInitializeAsync;

variable OnStateMachineInitializedAsyncDelegate

FOnStateMachineComponentInitializedAsync OnStateMachineInitializedAsyncDelegate;

Set from caller of initialize async function.


Friends

friend FInitiateServerCall

friend struct FInitiateServerCall(
    FInitiateServerCall 
);

friend FQueuedTransactionHelper

friend struct FQueuedTransactionHelper(
    FQueuedTransactionHelper 
);