2021-09-28 13:33:17 -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"
|
2022-02-24 08:19:23 -05:00
|
|
|
#include "StateTreeInstanceData.h"
|
2021-09-28 13:33:17 -04:00
|
|
|
#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:
|
|
|
|
|
|
2022-02-24 08:19:23 -05:00
|
|
|
/** @return Size required for the instance data in bytes. */
|
|
|
|
|
int32 GetInstanceDataSize() const;
|
|
|
|
|
|
2021-11-12 05:48:11 -05:00
|
|
|
/** @return Number of runtime data (Evaluators, Tasks, Conditions) in the runtime storage. */
|
|
|
|
|
int32 GetNumInstances() const { return Instances.Num(); }
|
2021-10-29 04:33:21 -04:00
|
|
|
|
2021-11-12 05:48:11 -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:01:08 -04:00
|
|
|
|
2021-11-12 05:48:11 -05:00
|
|
|
/** @return List of external data required by the state tree */
|
|
|
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetExternalDataDescs() const { return ExternalDataDescs; }
|
2021-09-28 13:33:17 -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; }
|
|
|
|
|
|
2022-02-24 08:19:23 -05:00
|
|
|
/** @return true is the tree asset is to be used at runtime. */
|
|
|
|
|
bool IsReadyToRun() const;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
/** 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:12 -05:00
|
|
|
TObjectPtr<UObject> EditorData;
|
2022-02-02 02:46:49 -05:00
|
|
|
|
|
|
|
|
// Hash of the editor data from last compile.
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
uint32 LastCompiledEditorDataHash = 0;
|
2021-09-28 13:33:17 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
2022-02-24 08:19:23 -05:00
|
|
|
|
|
|
|
|
/** Resolved references between data in the StateTree. */
|
|
|
|
|
void Link();
|
|
|
|
|
|
2021-09-28 13:33:17 -04:00
|
|
|
virtual void PostLoad() override;
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
|
|
|
|
|
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category = Common, Instanced)
|
2021-11-24 04:26:12 -05:00
|
|
|
TObjectPtr<UStateTreeSchema> Schema = nullptr;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2021-11-12 05:48:11 -05:00
|
|
|
/** Evaluators, Tasks, and Condition items */
|
2021-09-28 13:33:17 -04:00
|
|
|
UPROPERTY()
|
2022-02-24 08:19:23 -05:00
|
|
|
TArray<FInstancedStruct> Nodes;
|
2021-11-12 05:48:11 -05:00
|
|
|
|
|
|
|
|
/** Evaluators, Tasks, and Conditions runtime data. */
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<FInstancedStruct> Instances;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2021-11-24 04:26:12 -05:00
|
|
|
/** Blueprint based Evaluators, Tasks, and Conditions runtime data. */
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TArray<TObjectPtr<UObject>> InstanceObjects;
|
|
|
|
|
|
2022-03-10 21:51:53 -05:00
|
|
|
UPROPERTY(Transient)
|
2022-02-24 08:19:23 -05:00
|
|
|
FStateTreeInstanceData InstanceDataDefaultValue;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2021-11-12 05:48:11 -05:00
|
|
|
/** List of external data required by the state tree, creating during linking. */
|
2021-10-27 06:10:12 -04:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:48:11 -05:00
|
|
|
TArray<FStateTreeExternalDataDesc> ExternalDataDescs;
|
2021-09-28 13:33:17 -04:00
|
|
|
|
2021-11-03 07:01:08 -04:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:48:11 -05:00
|
|
|
int32 NumDataViews = 0;
|
2021-11-03 07:01:08 -04:00
|
|
|
|
2021-11-08 06:38:40 -05:00
|
|
|
UPROPERTY(Transient)
|
2021-11-12 05:48:11 -05:00
|
|
|
int32 ExternalDataBaseIndex = 0;
|
2021-11-08 06:38:40 -05:00
|
|
|
|
2021-09-28 13:33:17 -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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|