2021-09-28 13:33:00 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "Engine/DataAsset.h"
|
|
|
|
|
#include "StateTreeTypes.h"
|
|
|
|
|
#include "StateTreeSchema.h"
|
|
|
|
|
#include "InstancedStruct.h"
|
|
|
|
|
#include "StateTreePropertyBindings.h"
|
|
|
|
|
#include "StateTree.generated.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* StateTree asset. Contains the StateTree definition in both editor and runtime (baked) formats.
|
|
|
|
|
*/
|
|
|
|
|
UCLASS(BlueprintType)
|
|
|
|
|
class STATETREEMODULE_API UStateTree : public UDataAsset
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
UStateTree(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
2021-11-24 04:26:29 -05:00
|
|
|
~UStateTree();
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/** @return Script Struct that can be used to instantiate the runtime storage */
|
2021-11-12 05:49:31 -05:00
|
|
|
const UScriptStruct* GetInstanceStorageStruct() const { return InstanceStorageStruct; }
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/** @return Instance of the runtime storage that contains the default values */
|
2021-11-12 05:49:31 -05:00
|
|
|
const FInstancedStruct& GetInstanceStorageDefaultValue() const { return InstanceStorageDefaultValue; }
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** @return Number of runtime data (Evaluators, Tasks, Conditions) in the runtime storage. */
|
|
|
|
|
int32 GetNumInstances() const { return Instances.Num(); }
|
2021-10-29 04:37:57 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** @return Number of data views required for StateTree execution (Evaluators, Tasks, Conditions, External data). */
|
|
|
|
|
int32 GetNumDataViews() const { return NumDataViews; }
|
2021-11-03 07:03:18 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** @return Base index in data views for external data. */
|
|
|
|
|
int32 GetExternalDataBaseIndex() const { return ExternalDataBaseIndex; }
|
2021-11-08 06:40:19 -05:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** @return List of external data required by the state tree */
|
|
|
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetExternalDataDescs() const { return ExternalDataDescs; }
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/** @return Schema describing which inputs, evaluators, and tasks a StateTree can contain */
|
|
|
|
|
const UStateTreeSchema* GetSchema() const { return Schema; }
|
|
|
|
|
void SetSchema(UStateTreeSchema* InSchema) { Schema = InSchema; }
|
|
|
|
|
|
|
|
|
|
/** @return true is the tree asset is considered valid (e.g. at least one state) */
|
|
|
|
|
bool IsValidStateTree() const;
|
|
|
|
|
|
|
|
|
|
void ResolvePropertyPaths();
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
2021-11-24 04:26:29 -05:00
|
|
|
void OnPIEStarted(const bool bIsSimulating);
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
/** Resets the baked data to empty. */
|
|
|
|
|
void ResetBaked();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
// Edit time data for the StateTree, instance of UStateTreeEditorData
|
|
|
|
|
UPROPERTY()
|
2021-11-24 04:26:29 -05:00
|
|
|
TObjectPtr<UObject> EditorData;
|
2021-09-28 13:33:00 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void BeginDestroy() override;
|
|
|
|
|
virtual void PostLoad() override;
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
|
|
|
|
|
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/** Initializes the types and default values related to StateTree runtime storage */
|
2021-11-24 04:26:29 -05:00
|
|
|
void InitInstanceStorageType();
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-10-27 06:11:44 -04:00
|
|
|
/** Resolved references between data in the StateTree. */
|
|
|
|
|
void Link();
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category = Common, Instanced)
|
2021-11-24 04:26:29 -05:00
|
|
|
TObjectPtr<UStateTreeSchema> Schema = nullptr;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** Evaluators, Tasks, and Condition items */
|
2021-09-28 13:33:00 -04:00
|
|
|
UPROPERTY()
|
2021-11-12 05:49:31 -05:00
|
|
|
TArray<FInstancedStruct> Items;
|
|
|
|
|
|
|
|
|
|
/** Evaluators, Tasks, and Conditions runtime data. */
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<FInstancedStruct> Instances;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-24 04:26:29 -05:00
|
|
|
/** Blueprint based Evaluators, Tasks, and Conditions runtime data. */
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<TObjectPtr<UObject>> InstanceObjects;
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
/** Script Struct that can be used to instantiate the runtime storage */
|
|
|
|
|
UPROPERTY()
|
2021-11-24 04:26:29 -05:00
|
|
|
TObjectPtr<UScriptStruct> InstanceStorageStruct;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/** Offsets into the runtime type to quickly get a struct view to a specific Task or Evaluator */
|
2021-11-12 05:49:31 -05:00
|
|
|
TArray<FStateTreeInstanceStorageOffset> InstanceStorageOffsets;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/** Instance of the runtime storage that contains the default values. */
|
|
|
|
|
UPROPERTY()
|
2021-11-12 05:49:31 -05:00
|
|
|
FInstancedStruct InstanceStorageDefaultValue;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** List of external data required by the state tree, creating during linking. */
|
2021-10-27 06:11:44 -04:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:49:31 -05:00
|
|
|
TArray<FStateTreeExternalDataDesc> ExternalDataDescs;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-03 07:03:18 -04:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:49:31 -05:00
|
|
|
int32 NumDataViews = 0;
|
2021-11-03 07:03:18 -04:00
|
|
|
|
2021-11-08 06:40:19 -05:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:49:31 -05:00
|
|
|
int32 ExternalDataBaseIndex = 0;
|
2021-11-08 06:40:19 -05:00
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
UPROPERTY()
|
|
|
|
|
FStateTreePropertyBindings PropertyBindings;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<FBakedStateTreeState> States;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<FBakedStateTransition> Transitions;
|
|
|
|
|
|
|
|
|
|
friend struct FStateTreeInstance;
|
|
|
|
|
friend struct FStateTreeExecutionContext;
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
friend struct FStateTreeBaker;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|