Skip to content

USMPreviewObject¶

Module: SMPreviewEditor

#include <SMPreviewObject.h>

Inherits from UObject

Description¶

class USMPreviewObject;

Single object per blueprint to manage simulation data.

Public Functions¶

Name
USMPreviewObject()
virtual ~USMPreviewObject() override
virtual void Serialize(FArchive & Ar) override
virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent & PropertyChangedEvent) override
virtual void PostEditUndo() override
virtual bool IsEditorOnly() const override
DECLARE_MULTICAST_DELEGATE_OneParam(FOnPreviewObjectChanged , USMPreviewObject * )
DECLARE_MULTICAST_DELEGATE_OneParam(FOnPreviewWorldChanged , UWorld * )
USMInstance * InitializeStateMachine(UObject * InContext)
void ShutdownStateMachine()
void SetFromBlueprint(UBlueprint * Blueprint)
ASMPreviewStateMachineActor * GetPreviewStateMachineActor() const
void SetPreviewWorld(UWorld * InWorld, const bool bModify =false)
void SetCurrentWorld(UWorld * InWorld)
void UpdateGameMode()
void BroadcastWorldRefreshRequired()
void SpawnAllActors()
void DestroyAllActors()
void RefreshPreviewWorldActors()
bool ContainsActor(AActor * CompareActor) const
void SaveAllActorReferences()
void RestoreAllActorReferences()
bool IsSimulationRunning() const
UWorld * GetPreviewWorld() const
UWorld * GetCurrentWorld() const
USMInstance * GetStateMachineTemplate() const
void SetSimulatedStateMachineInstance(USMInstance * InInstance)
USMInstance * GetSimulatedStateMachineInstance() const
TSubclassOf< AGameModeBase > GetGameMode() const
TSubclassOf< UGameInstance > GetGameInstance() const
bool ShouldPossessPawnContext() const
bool ShouldUseNonActorContext() const
bool ShouldUseGameInstanceAsContext() const
void SetUseGameInstanceAsContext(bool bNewValue)
void SetContextActor(AActor * InActor)
AActor * GetContextActor() const
void SetContextObject(UObject * InObject)
UObject * GetContextObject() const
void AddPreviewActor(FSMPreviewObjectSpawner & NewPreviewObject)
void RemovePreviewActor(AActor * ActorToRemove)
void NotifySimulationStarted()
void NotifySimulationEnded()
void BindActorDelegates()
void ReleaseActorHandles()

Protected Functions¶

Name
void OnWorldDestroyed(UWorld * World)
void GetAllActorReferences(UObject * InObject, TMap< FName, FName > & PropertyNameValue) const
void RestoreActorReferences(UObject * InObject, ULevel * InLevel, const TMap< FName, FName > & PropertyNameValue)
void SpawnActorForWorld(FSMPreviewObjectSpawner & InOutSpawner)
AActor * SpawnActorForWorld(UWorld * InWorld, UClass * ActorClass, AActor * ActorTemplate, const FTransform & Transform)
void DestroyActor(AActor * Actor)
FSMPreviewObjectSpawner * GetPreviewSpawnerFromActor(AActor * Actor)
void BuildActorMap()

Public Attributes¶

Name
FOnPreviewObjectChanged OnPreviewObjectChangedEvent
FOnPreviewObjectChanged OnWorldRefreshRequiredEvent
FOnPreviewObjectChanged OnSimulationStartedEvent
FOnPreviewObjectChanged OnSimulationEndedEvent
FOnPreviewWorldChanged OnCurrentWorldChangedEvent

Public Functions Documentation¶

function USMPreviewObject¶

USMPreviewObject()

function ~USMPreviewObject¶

virtual ~USMPreviewObject() override

function Serialize¶

virtual void Serialize(
    FArchive & Ar
) override

function PostEditChangeChainProperty¶

virtual void PostEditChangeChainProperty(
    FPropertyChangedChainEvent & PropertyChangedEvent
) override

function PostEditUndo¶

virtual void PostEditUndo() override

function IsEditorOnly¶

inline virtual bool IsEditorOnly() const override

function DECLARE_MULTICAST_DELEGATE_OneParam¶

DECLARE_MULTICAST_DELEGATE_OneParam(
    FOnPreviewObjectChanged ,
    USMPreviewObject * 
)

function DECLARE_MULTICAST_DELEGATE_OneParam¶

DECLARE_MULTICAST_DELEGATE_OneParam(
    FOnPreviewWorldChanged ,
    UWorld * 
)

function InitializeStateMachine¶

USMInstance * InitializeStateMachine(
    UObject * InContext
)

Initialize the live state machine instance.


function ShutdownStateMachine¶

void ShutdownStateMachine()

Gracefully shutdown the state machine.


function SetFromBlueprint¶

void SetFromBlueprint(
    UBlueprint * Blueprint
)

Sets state machine properties from a blueprint.


function GetPreviewStateMachineActor¶

inline ASMPreviewStateMachineActor * GetPreviewStateMachineActor() const

Deprecated:

This function is deprecated. There is now only a simulated state machine actor that shouldn't be accessed.


function SetPreviewWorld¶

void SetPreviewWorld(
    UWorld * InWorld,
    const bool bModify =false
)

Call before use so the preview object knows what world to spawn and destroy actors.


function SetCurrentWorld¶

void SetCurrentWorld(
    UWorld * InWorld
)

The current world: either simulation or preview.


function UpdateGameMode¶

void UpdateGameMode()

Deprecated:

This function is deprecated. Use BroadcastWorldRefreshRequired() instead.


function BroadcastWorldRefreshRequired¶

void BroadcastWorldRefreshRequired()

Signal that the world should be refreshed.


function SpawnAllActors¶

void SpawnAllActors()

Spawns context and all preview actors.


function DestroyAllActors¶

void DestroyAllActors()

Destroys context and all preview actors.


function RefreshPreviewWorldActors¶

void RefreshPreviewWorldActors()

Signals to refresh actors, such as after a package has saved.


function ContainsActor¶

bool ContainsActor(
    AActor * CompareActor
) const

Checks if the actor is contained in the spawned actors.


function SaveAllActorReferences¶

void SaveAllActorReferences()

Save actor reference paths so they can be restored after an editor reset.


function RestoreAllActorReferences¶

void RestoreAllActorReferences()

Use saved actor paths to find the real actor references in the world.


function IsSimulationRunning¶

bool IsSimulationRunning() const

Checks if a state machine is currently running for simulation.


function GetPreviewWorld¶

inline UWorld * GetPreviewWorld() const

The current preview world if one exists.


function GetCurrentWorld¶

inline UWorld * GetCurrentWorld() const

The preview or simulation world.


function GetStateMachineTemplate¶

inline USMInstance * GetStateMachineTemplate() const

function SetSimulatedStateMachineInstance¶

void SetSimulatedStateMachineInstance(
    USMInstance * InInstance
)

Deprecated:

This function is deprecated. The simulated state machine should only be managed internally.


function GetSimulatedStateMachineInstance¶

inline USMInstance * GetSimulatedStateMachineInstance() const

Deprecated:

This function is deprecated. The simulated state machine should only be managed internally.


function GetGameMode¶

inline TSubclassOf< AGameModeBase > GetGameMode() const

Retrieve the game mode for this preview object.


function GetGameInstance¶

inline TSubclassOf< UGameInstance > GetGameInstance() const

Retrieve the game instance class for this preview object.


function ShouldPossessPawnContext¶

inline bool ShouldPossessPawnContext() const

If a pawn context should be possessed.


function ShouldUseNonActorContext¶

bool ShouldUseNonActorContext() const

If we aren't using a standard actor context.


function ShouldUseGameInstanceAsContext¶

inline bool ShouldUseGameInstanceAsContext() const

If the game instance should be used as the context.


function SetUseGameInstanceAsContext¶

void SetUseGameInstanceAsContext(
    bool bNewValue
)

Update whether the game instance should be used as a context.


function SetContextActor¶

void SetContextActor(
    AActor * InActor
)

Deprecated:

This function is deprecated. Use SetContextObject() instead.


function GetContextActor¶

AActor * GetContextActor() const

Deprecated:

This function is deprecated. Use GetContextObject() instead.


function SetContextObject¶

void SetContextObject(
    UObject * InObject
)

Set the context object for the simulation.


function GetContextObject¶

UObject * GetContextObject() const

Retrieve the context object for the simulation.


function AddPreviewActor¶

void AddPreviewActor(
    FSMPreviewObjectSpawner & NewPreviewObject
)

Create an initial template and spawn the actor.


function RemovePreviewActor¶

void RemovePreviewActor(
    AActor * ActorToRemove
)

Searches for the preview spawner associated with this actor and removes it and despawns it.


function NotifySimulationStarted¶

void NotifySimulationStarted()

Inform the preview object simulation has started.


function NotifySimulationEnded¶

void NotifySimulationEnded()

Inform the preview object simulation has ended.


function BindActorDelegates¶

void BindActorDelegates()

Bind to engine actor delegates.


function ReleaseActorHandles¶

void ReleaseActorHandles()

Safely release and reset all delegate handles.


Protected Functions Documentation¶

function OnWorldDestroyed¶

void OnWorldDestroyed(
    UWorld * World
)

function GetAllActorReferences¶

void GetAllActorReferences(
    UObject * InObject,
    TMap< FName, FName > & PropertyNameValue
) const

function RestoreActorReferences¶

void RestoreActorReferences(
    UObject * InObject,
    ULevel * InLevel,
    const TMap< FName, FName > & PropertyNameValue
)

function SpawnActorForWorld¶

void SpawnActorForWorld(
    FSMPreviewObjectSpawner & InOutSpawner
)

function SpawnActorForWorld¶

AActor * SpawnActorForWorld(
    UWorld * InWorld,
    UClass * ActorClass,
    AActor * ActorTemplate,
    const FTransform & Transform
)

function DestroyActor¶

void DestroyActor(
    AActor * Actor
)

Destroy an actor but will not null out actor from the object spawner.


function GetPreviewSpawnerFromActor¶

FSMPreviewObjectSpawner * GetPreviewSpawnerFromActor(
    AActor * Actor
)

Find the preview reference from an actor.


function BuildActorMap¶

void BuildActorMap()

Quick access to finding a preview spawner given an actor. Should be rebuilt whenever PreviewObjects is modified.


Public Attributes Documentation¶

variable OnPreviewObjectChangedEvent¶

FOnPreviewObjectChanged OnPreviewObjectChangedEvent;

When a property of the preview object has changed.


variable OnWorldRefreshRequiredEvent¶

FOnPreviewObjectChanged OnWorldRefreshRequiredEvent;

When the preview object needs a new world.


variable OnSimulationStartedEvent¶

FOnPreviewObjectChanged OnSimulationStartedEvent;

When the simulation first starts.


variable OnSimulationEndedEvent¶

FOnPreviewObjectChanged OnSimulationEndedEvent;

When the simulation ends.


variable OnCurrentWorldChangedEvent¶

FOnPreviewWorldChanged OnCurrentWorldChangedEvent;

When a new world has been set such as from preview to simulation or back.


Private Attributes Documentation¶

variable OnWorldDestroyedHandle¶

FDelegateHandle OnWorldDestroyedHandle;

variable PieStartedHandle¶

FDelegateHandle PieStartedHandle;

variable ActorMovingHandle¶

FDelegateHandle ActorMovingHandle;

variable ActorMovedHandle¶

FDelegateHandle ActorMovedHandle;

variable ActorPropertyChangeHandle¶

FDelegateHandle ActorPropertyChangeHandle;

variable PreviewObjects¶

TArray< FSMPreviewObjectSpawner > PreviewObjects;

All objects to spawn into the preview world.


variable ActorNameToPreviewIndex¶

TMap< FName, int32 > ActorNameToPreviewIndex;

Actor name to the index of the PreviewObjects array.


variable ContextName¶

FName ContextName;

Actor name to use as the context.


variable CachedContextObject¶

TObjectPtr< UObject > CachedContextObject;

Current context actor for this session.


variable GameMode¶

TSubclassOf< AGameModeBase > GameMode;

The game mode to use when simulating.


variable GameInstance¶

TSubclassOf< UGameInstance > GameInstance;

The game instance to use when simulating.


variable bUseGameInstanceAsContext¶

bool bUseGameInstanceAsContext;

If the game instance should be used as a context object.


variable bPossessPawnContext¶

bool bPossessPawnContext;

Possess a pawn context with the default player controller when simulating.


variable StateMachineTemplate¶

USMInstance * StateMachineTemplate;

The state machine to spawn into the simulation world.


variable SimulatedStateMachineInstance¶

TObjectPtr< USMInstance > SimulatedStateMachineInstance;

The SIMULATED state machine that is running. Hosted under a PreviewStateMachineActor if there is a valid world. This is set externally when a user starts simulation.


variable ActorPropertyToActorName¶

TMap< FName, FName > ActorPropertyToActorName;

Full property names mapped to actor names.


variable SimulatedStateMachineActor¶

TObjectPtr< ASMPreviewStateMachineActor > SimulatedStateMachineActor;

An actor to host a SIMULATED state machine.


variable PreviewWorld¶

TObjectPtr< UWorld > PreviewWorld;

The PREVIEW world if one exists.


variable CurrentWorld¶

TObjectPtr< UWorld > CurrentWorld;

Either preview or simulation.


variable SpawnedActors¶

TArray< TObjectPtr< AActor > > SpawnedActors;

Actors currently spawned in the world.


variable bSpawningActor¶

bool bSpawningActor;

True only during a spawn.


variable bDontModify¶

bool bDontModify;

Prevents Modify() from being called.


variable bIsSaving¶

bool bIsSaving;

True during serialize writing.