Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Private/StateTreeReference.cpp
Yoan StAmant 5875739cb2 [StateTree] added StateTreeReference type customization
- StateTree asset allowed by a StateTreeReference can be filtered by using "meta=(schema="SomeSchema")" on the UPROPERTY of type StateTreeReference.
#rnx
#rb mikko.mononen
#preflight 627a6fd7e713fc6e2c4cddae

[CL 20122645 by Yoan StAmant in ue5-main branch]
2022-05-10 10:15:17 -04:00

61 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "StateTreeReference.h"
#include "StateTree.h"
#if WITH_EDITOR
#include "Editor.h"
#endif
FStateTreeReference::FStateTreeReference()
{
#if WITH_EDITOR
// Make sure any modifications to the parameters since the last sync (PostSerialize) won't cause runtime issues.
PIEHandle = FEditorDelegates::PreBeginPIE.AddLambda([this](const bool bBegan)
{
if (RequiresParametersSync())
{
SyncParameters();
UE_LOG(LogStateTree, Warning, TEXT("Parameters for '%s' stored in StateTreeReference were auto-fixed to be usable at runtime."), *GetNameSafe(StateTree));
}
});
#endif
}
FStateTreeReference::~FStateTreeReference()
{
#if WITH_EDITOR
// Unregister all our delegates
FEditorDelegates::PreBeginPIE.Remove(PIEHandle);
#endif
}
#if WITH_EDITOR
void FStateTreeReference::PostSerialize(const FArchive& Ar)
{
if (Ar.IsLoading() & Ar.IsPersistent())
{
// This might modify the object but we don't want to dirty on load
SyncParameters();
}
}
void FStateTreeReference::SyncParameters(FInstancedPropertyBag& ParametersToSync) const
{
if (StateTree == nullptr)
{
ParametersToSync.Reset();
}
else
{
ParametersToSync.MigrateToNewBagInstance(StateTree->GetDefaultParameters());
}
}
bool FStateTreeReference::RequiresParametersSync() const
{
return (StateTree == nullptr && Parameters.IsValid())
|| (StateTree != nullptr && StateTree->GetDefaultParameters().GetPropertyBagStruct() != Parameters.GetPropertyBagStruct());
}
#endif // WITH_EDITOR