You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Deprecated per state evaluators and moved them to global to the tree - Tick evals once per Tick() - Updated editor node customizations to work on UStateTreeEditorData - Added separate detail customization for UStateTreeEditorData #jira UE-147508 #rb Yoan.StAmant #preflight 62820e55046b81bf93911605 [CL 20221385 by mikko mononen in ue5-main branch]
189 lines
5.3 KiB
C++
189 lines
5.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Engine/DataAsset.h"
|
|
#include "StateTreeTypes.h"
|
|
#include "StateTreeSchema.h"
|
|
#include "InstancedStruct.h"
|
|
#include "StateTreePropertyBindings.h"
|
|
#include "StateTreeInstanceData.h"
|
|
#include "StateTree.generated.h"
|
|
|
|
|
|
/** Custom serialization version for StateTree Asset */
|
|
struct STATETREEMODULE_API FStateTreeCustomVersion
|
|
{
|
|
enum Type
|
|
{
|
|
// Before any version changes were made in the plugin
|
|
BeforeCustomVersionWasAdded = 0,
|
|
// Separated conditions to shared instance data.
|
|
SharedInstanceData,
|
|
// Moved evaluators to be global.
|
|
GlobalEvaluators,
|
|
|
|
// -----<new versions can be added above this line>-------------------------------------------------
|
|
VersionPlusOne,
|
|
LatestVersion = VersionPlusOne - 1
|
|
};
|
|
|
|
/** The GUID for this custom version number */
|
|
const static FGuid GUID;
|
|
|
|
private:
|
|
FStateTreeCustomVersion() {}
|
|
};
|
|
|
|
/**
|
|
* StateTree asset. Contains the StateTree definition in both editor and runtime (baked) formats.
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class STATETREEMODULE_API UStateTree : public UDataAsset
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
|
|
/** @return Default value for the instance data. */
|
|
const FStateTreeInstanceData& GetInstanceDataDefaultValue() const { return InstanceDataDefaultValue; }
|
|
|
|
/**
|
|
* @todo: This should return different data for each thread.
|
|
* @return Shared instance data.
|
|
*/
|
|
const FStateTreeInstanceData& GetSharedInstanceData() const { return SharedInstanceData; }
|
|
|
|
/** @return Number of data views required for StateTree execution (Evaluators, Tasks, Conditions, External data). */
|
|
int32 GetNumDataViews() const { return NumDataViews; }
|
|
|
|
/** @return List of external data required by the state tree */
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetExternalDataDescs() const { return ExternalDataDescs; }
|
|
|
|
/** @return List of named external data enforced by the schema that must be provided through the execution context. */
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetNamedExternalDataDescs() const { return NamedExternalDataDescs; }
|
|
|
|
/** @return List of default parameters of the state tree. Default parameter values can be overridden at runtime by the execution context. */
|
|
const FInstancedPropertyBag& GetDefaultParameters() const { return Parameters; }
|
|
|
|
/** @return true if the tree asset can be used at runtime. */
|
|
bool IsReadyToRun() const;
|
|
|
|
#if WITH_EDITOR
|
|
/** Resets the compiled data to empty. */
|
|
void ResetCompiled();
|
|
#endif
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
/** Edit time data for the StateTree, instance of UStateTreeEditorData */
|
|
UPROPERTY()
|
|
TObjectPtr<UObject> EditorData;
|
|
|
|
/** Hash of the editor data from last compile. */
|
|
UPROPERTY()
|
|
uint32 LastCompiledEditorDataHash = 0;
|
|
#endif
|
|
|
|
protected:
|
|
|
|
/**
|
|
* Resolves references between data in the StateTree.
|
|
* @return true if all references to internal and external data are resolved properly, false otherwise.
|
|
*/
|
|
[[nodiscard]] bool Link();
|
|
|
|
virtual void PostLoad() override;
|
|
virtual void Serialize(FStructuredArchiveRecord Record) override;
|
|
|
|
#if WITH_EDITOR
|
|
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
|
#endif
|
|
|
|
private:
|
|
|
|
/**
|
|
* Reset the data generated by Link(), this in turn will cause IsReadyToRun() to return false.
|
|
* Used during linking, or to invalidate the linked data when data version is old (requires recompile).
|
|
*/
|
|
void ResetLinked();
|
|
|
|
// Properties
|
|
|
|
UPROPERTY(Instanced)
|
|
TObjectPtr<UStateTreeSchema> Schema = nullptr;
|
|
|
|
/**
|
|
* Parameters that could be used for bindings within the Tree.
|
|
* Default values are stored within the asset but StateTreeReference can be used to parameterized the tree.
|
|
* @see FStateTreeReference
|
|
*/
|
|
UPROPERTY()
|
|
FInstancedPropertyBag Parameters;
|
|
|
|
/** Evaluators, Tasks, and Condition items */
|
|
UPROPERTY()
|
|
TArray<FInstancedStruct> Nodes;
|
|
|
|
/** Evaluators, Tasks, and Conditions runtime data. */
|
|
UPROPERTY()
|
|
TArray<FInstancedStruct> Instances;
|
|
|
|
/** Blueprint based Evaluators, Tasks, and Conditions runtime data. */
|
|
UPROPERTY()
|
|
TArray<TObjectPtr<UObject>> InstanceObjects;
|
|
|
|
/** Conditions runtime data. */
|
|
UPROPERTY()
|
|
TArray<FInstancedStruct> SharedInstances;
|
|
|
|
/** Blueprint Conditions runtime data. */
|
|
UPROPERTY()
|
|
TArray<TObjectPtr<UObject>> SharedInstanceObjects;
|
|
|
|
UPROPERTY(Transient)
|
|
FStateTreeInstanceData InstanceDataDefaultValue;
|
|
|
|
UPROPERTY(Transient)
|
|
FStateTreeInstanceData SharedInstanceData;
|
|
|
|
/** List of external data required by the state tree, created during linking. */
|
|
UPROPERTY(Transient)
|
|
TArray<FStateTreeExternalDataDesc> ExternalDataDescs;
|
|
|
|
/** List of names external data enforced by the schema, created at compilation. */
|
|
UPROPERTY()
|
|
TArray<FStateTreeExternalDataDesc> NamedExternalDataDescs;
|
|
|
|
UPROPERTY()
|
|
uint16 EvaluatorsBegin = 0;
|
|
|
|
UPROPERTY()
|
|
uint16 EvaluatorsNum = 0;
|
|
|
|
UPROPERTY(Transient)
|
|
int32 NumDataViews = 0;
|
|
|
|
UPROPERTY(Transient)
|
|
int32 ExternalDataBaseIndex = 0;
|
|
|
|
/** Data view index of the tree parameters */
|
|
UPROPERTY()
|
|
int32 DefaultParametersDataViewIndex = INDEX_NONE;
|
|
|
|
UPROPERTY()
|
|
FStateTreePropertyBindings PropertyBindings;
|
|
|
|
UPROPERTY()
|
|
TArray<FCompactStateTreeState> States;
|
|
|
|
UPROPERTY()
|
|
TArray<FCompactStateTransition> Transitions;
|
|
|
|
friend struct FStateTreeInstance;
|
|
friend struct FStateTreeExecutionContext;
|
|
#if WITH_EDITORONLY_DATA
|
|
friend struct FStateTreeCompiler;
|
|
#endif
|
|
};
|
|
|