Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Public/StateTreeReference.h
mikko mononen 0d1ace8323 StateTree: StateTreeComponent improvements
- Added option to start the StateTree automatically on BeginPlay
- StateTreeComponentSchema: allow to specify which actor class to expect the StateTree to run on (allows to bind to Actor specific data directly)
- Fixed FStateTreeReference parameter update on BP instance (the struct gets copied, which cause issues with the delegate handle)

#rb Mieszko.Zielinski
#preflight 630c70bb0345de4ccf7c8b51

[CL 21685020 by mikko mononen in ue5-main branch]
2022-08-29 14:47:43 -04:00

83 lines
2.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "StateTreeTypes.h"
#include "StateTreeReference.generated.h"
class UStateTree;
/**
* Struct to hold reference to a StateTree asset along with values to parameterized it.
*/
USTRUCT()
struct STATETREEMODULE_API FStateTreeReference
{
GENERATED_BODY()
/** @return true if the reference is set. */
bool IsValid() const
{
return StateTree != nullptr;
}
/** Sets the StateTree asset and referenced parameters. */
void SetStateTree(UStateTree* NewStateTree)
{
StateTree = NewStateTree;
SyncParameters();
}
/** @return const pointer to the referenced StateTree asset. */
const UStateTree* GetStateTree() const
{
return StateTree;
}
/** @return pointer to the referenced StateTree asset. */
UStateTree* GetMutableStateTree()
{
return StateTree;
}
/** @return reference to the parameters for the referenced StateTree asset. */
const FInstancedPropertyBag& GetParameters() const
{
ConditionallySyncParameters();
return Parameters;
}
/** @return reference to the parameters for the referenced StateTree asset. */
FInstancedPropertyBag& GetMutableParameters()
{
ConditionallySyncParameters();
return Parameters;
}
/**
* Enforce self parameters to be compatible with those exposed by the selected StateTree asset.
*/
void SyncParameters() { SyncParametersToMatchStateTree(Parameters); }
/**
* Sync provided parameters to be compatible with those exposed by the selected StateTree asset.
*/
void SyncParametersToMatchStateTree(FInstancedPropertyBag& ParametersToSync) const;
/**
* Indicates if current parameters are compatible with those available in the selected StateTree asset.
* @return true when parameters requires to be synced to be compatible with those available in the selected StateTree asset, false otherwise.
*/
bool RequiresParametersSync() const;
/** Sync parameters to match the asset if required. */
void ConditionallySyncParameters() const;
protected:
UPROPERTY(EditAnywhere, Category = "")
TObjectPtr<UStateTree> StateTree = nullptr;
UPROPERTY(EditAnywhere, Category = "", meta = (FixedLayout))
FInstancedPropertyBag Parameters;
};