Skip to content

USMUtils

Module: SMSystem

#include <SMUtils.h>

Description

class USMUtils;

Internal helpers around utilizing state machine instances.

Public Functions

Name
bool GenerateStateMachine(UObject * Instance, FSMStateMachine & StateMachineOut, const TSet< FStructProperty * > & RunTimeProperties, bool bForCompile =false)
bool TryGetStateMachinePropertiesForClass(const UClass * Class, TSet< FStructProperty * > & PropertiesOut, FGuid & RootGuid, EFieldIteratorFlags::SuperClassFlags SuperFlags =EFieldIteratorFlags::ExcludeSuper)
bool TryGetGraphPropertiesForClass(const UClass * Class, TSet< FProperty * > & PropertiesOut, const TSharedPtr< FSMCachedPropertyData, ESPMode::ThreadSafe > & CachedPropertyData)
void TryGetAllOwners(const FSMNode_Base * Node, TArray< const FSMNode_Base * > & OwnersOrdered, const USMInstance * LimitToInstance =nullptr)
FString BuildGuidPathFromNodes(const TArray< const FSMNode_Base * > & Nodes, TMap< FString, int32 > * MappedPaths =nullptr)
FGuid PathToGuid(const FString & UnhashedPath, FGuid * OutGuid =nullptr)
UObject * FindTemplateFromInstance(const USMInstance * Instance, const FName & TemplateName)
bool TryGetAllReferenceTemplatesFromInstance(const USMInstance * Instance, TSet< USMInstance * > & TemplatesOut, bool bIncludeNested =false)
template \<typename T >
T *
FindControllerFromContext(UObject * InContextObject)
void EnableInputForObject(APlayerController * InPlayerController, UObject * InObject, TObjectPtr< UInputComponent > & InOutComponent, int32 InputPriority, bool bBlockInput, bool bPushPopInput)
void DisableInput(UWorld * InWorld, TObjectPtr< UInputComponent > & InOutComponent)
void HandlePawnControllerChange(APawn * InPawn, AController * InController, UObject * InObject, TObjectPtr< UInputComponent > & InOutComponent, int32 InputPriority, bool bBlockInput)
void ActivateStateNetOrLocal(FSMState_Base * InState, bool bValue, bool bSetAllParents =false, bool bActivateNow =true)
template \<typename T >
bool
TryGetAllRuntimeNodesFromInstance(USMInstance * Instance, TSet< T * > & NodesOut)
template \<typename T >
void
BlueprintPropertyToNativeProperty(FProperty * Property, UObject * Scope, TArray< T > & OutNativeProperties)
template \<typename T >
void
BlueprintPropertyToNativeProperty(FProperty * Property, UObject * Scope, TArray< T * > & OutNativeProperties)
template \<typename T >
int32
InsertOrAddToArray(TArray< T > & InArray, const T & InObject, int32 InIndex)
template \<typename T >
void
RemoveAtOrPopFromArray(TArray< T > & InArray, int32 InIndex)

Public Functions Documentation

function GenerateStateMachine

static bool GenerateStateMachine(
    UObject * Instance,
    FSMStateMachine & StateMachineOut,
    const TSet< FStructProperty * > & RunTimeProperties,
    bool bForCompile =false
)

Compiles a state machine from an object. (Should be SMInstance). Guid needs to be set correctly prior to calling.

Parameters:

Instance
The object containing instance data. Should be an USMInstance.
StateMachineOut
The state machine struct which will be assembled.
RunTimeProperties
Class properties which will be used to create the state machine.
bForCompile
Prevents the full initialize sequence from running on references and used to gather information for compile.

function TryGetStateMachinePropertiesForClass

static bool TryGetStateMachinePropertiesForClass(
    const UClass * Class,
    TSet< FStructProperty * > & PropertiesOut,
    FGuid & RootGuid,
    EFieldIteratorFlags::SuperClassFlags SuperFlags =EFieldIteratorFlags::ExcludeSuper
)

Locate the properties required for a state machine looking backwards up the parent classes.


function TryGetGraphPropertiesForClass

static bool TryGetGraphPropertiesForClass(
    const UClass * Class,
    TSet< FProperty * > & PropertiesOut,
    const TSharedPtr< FSMCachedPropertyData, ESPMode::ThreadSafe > & CachedPropertyData
)

Locate any Graph Properties for a given class.


function TryGetAllOwners

static void TryGetAllOwners(
    const FSMNode_Base * Node,
    TArray< const FSMNode_Base * > & OwnersOrdered,
    const USMInstance * LimitToInstance =nullptr
)

Look up all node owners. Results will be ordered oldest to newest with the given Node as the last entry.


function BuildGuidPathFromNodes

static FString BuildGuidPathFromNodes(
    const TArray< const FSMNode_Base * > & Nodes,
    TMap< FString, int32 > * MappedPaths =nullptr
)

Construct a path of guids from the nodes.


function PathToGuid

static FGuid PathToGuid(
    const FString & UnhashedPath,
    FGuid * OutGuid =nullptr
)

Convert an unhashed path to a hashed guid path.


function FindTemplateFromInstance

static UObject * FindTemplateFromInstance(
    const USMInstance * Instance,
    const FName & TemplateName
)

Search up parents for a default sub objects for a template.


function TryGetAllReferenceTemplatesFromInstance

static bool TryGetAllReferenceTemplatesFromInstance(
    const USMInstance * Instance,
    TSet< USMInstance * > & TemplatesOut,
    bool bIncludeNested =false
)

Find all reference templates from an instance. Nested children shouldn't be found after a compile or during run-time!


function FindControllerFromContext

template <typename T >
static inline T * FindControllerFromContext(
    UObject * InContextObject
)

Attempt to find a controller of type T from the context object.


function EnableInputForObject

static void EnableInputForObject(
    APlayerController * InPlayerController,
    UObject * InObject,
    TObjectPtr< UInputComponent > & InOutComponent,
    int32 InputPriority,
    bool bBlockInput,
    bool bPushPopInput
)

Create an input component for an object if necessary and register with a player controller.


function DisableInput

static void DisableInput(
    UWorld * InWorld,
    TObjectPtr< UInputComponent > & InOutComponent
)

Disable input for all player controllers using this input component.


function HandlePawnControllerChange

static void HandlePawnControllerChange(
    APawn * InPawn,
    AController * InController,
    UObject * InObject,
    TObjectPtr< UInputComponent > & InOutComponent,
    int32 InputPriority,
    bool bBlockInput
)

Call when a controller has changed for a tracked pawn.


function ActivateStateNetOrLocal

static void ActivateStateNetOrLocal(
    FSMState_Base * InState,
    bool bValue,
    bool bSetAllParents =false,
    bool bActivateNow =true
)

Change the active state of a state machine instance, handling replication or local.


function TryGetAllRuntimeNodesFromInstance

template <typename T >
static inline bool TryGetAllRuntimeNodesFromInstance(
    USMInstance * Instance,
    TSet< T * > & NodesOut
)

Iterate properties of an instance finding all structs derived from the given type (such as FSMNode_Base).


function BlueprintPropertyToNativeProperty

template <typename T >
static inline void BlueprintPropertyToNativeProperty(
    FProperty * Property,
    UObject * Scope,
    TArray< T > & OutNativeProperties
)

function BlueprintPropertyToNativeProperty

template <typename T >
static inline void BlueprintPropertyToNativeProperty(
    FProperty * Property,
    UObject * Scope,
    TArray< T * > & OutNativeProperties
)

function InsertOrAddToArray

template <typename T >
static inline int32 InsertOrAddToArray(
    TArray< T > & InArray,
    const T & InObject,
    int32 InIndex
)

Insert an element into the array if the index is valid, otherwise add to the end.

Return: The index the element was inserted to.


function RemoveAtOrPopFromArray

template <typename T >
static inline void RemoveAtOrPopFromArray(
    TArray< T > & InArray,
    int32 InIndex
)

Remove an element from the array if the index is valid, otherwise remove from the end.