2024-03-20 08:28:58 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "StateTreeInstanceData.h"
|
|
|
|
|
#include "StateTreeReference.h"
|
|
|
|
|
#include "StateTreeTaskBase.h"
|
|
|
|
|
|
|
|
|
|
#include "StateTreeRunParallelStateTreeTask.generated.h"
|
|
|
|
|
|
|
|
|
|
USTRUCT()
|
|
|
|
|
struct FStateTreeRunParallelStateTreeTaskInstanceData
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
/** State tree and parameters that will be run when this task is started. */
|
2024-03-22 11:55:18 -04:00
|
|
|
UPROPERTY(EditAnywhere, Category = "Parameter", meta=(SchemaCanBeOverriden))
|
2024-03-20 08:28:58 -04:00
|
|
|
FStateTreeReference StateTree;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(Transient)
|
|
|
|
|
FStateTreeInstanceData TreeInstanceData;
|
2024-04-03 07:16:44 -04:00
|
|
|
|
|
|
|
|
UPROPERTY(Transient)
|
|
|
|
|
TObjectPtr<const UStateTree> RunningStateTree = nullptr;
|
2024-03-20 08:28:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Task that will run another state tree in the current state while allowing the current tree to continue selection and process of child state.
|
|
|
|
|
* It will succeed, fail or run depending on the result of the parallel tree.
|
|
|
|
|
* Less efficient then Linked Asset state, it has the advantage of allowing multiple trees to run in parallel.
|
|
|
|
|
*/
|
|
|
|
|
USTRUCT(meta = (DisplayName = "Run Parallel Tree", Category = "Common"))
|
2024-04-12 06:04:01 -04:00
|
|
|
struct STATETREEMODULE_API FStateTreeRunParallelStateTreeTask : public FStateTreeTaskCommonBase
|
2024-03-20 08:28:58 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
using FInstanceDataType = FStateTreeRunParallelStateTreeTaskInstanceData;
|
|
|
|
|
|
|
|
|
|
FStateTreeRunParallelStateTreeTask();
|
|
|
|
|
|
2024-04-12 06:04:01 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
// Sets event handling priority
|
|
|
|
|
void SetEventHandlingPriority(const EStateTreeTransitionPriority NewPriority)
|
|
|
|
|
{
|
|
|
|
|
EventHandlingPriority = NewPriority;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-03-20 08:28:58 -04:00
|
|
|
protected:
|
|
|
|
|
virtual const UStruct* GetInstanceDataType() const override { return FInstanceDataType::StaticStruct(); }
|
|
|
|
|
|
|
|
|
|
virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transitions) const override;
|
|
|
|
|
virtual EStateTreeRunStatus Tick(FStateTreeExecutionContext& Context, const float DeltaTime) const override;
|
2024-04-12 06:04:01 -04:00
|
|
|
virtual void TriggerTransitions(FStateTreeExecutionContext& Context) const override;
|
2024-03-20 08:28:58 -04:00
|
|
|
virtual void ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
2024-04-12 06:04:01 -04:00
|
|
|
virtual EDataValidationResult Compile(FStateTreeDataView InstanceDataView, TArray<FText>& ValidationMessages) override;
|
2024-03-20 08:28:58 -04:00
|
|
|
virtual void PostEditInstanceDataChangeChainProperty(const FPropertyChangedChainEvent& PropertyChangedEvent, FStateTreeDataView InstanceDataView) override;
|
2024-03-21 08:38:57 -04:00
|
|
|
virtual void PostLoad(FStateTreeDataView InstanceDataView) override;
|
2024-04-05 04:18:10 -04:00
|
|
|
virtual FText GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting = EStateTreeNodeFormatting::Text) const override;
|
2024-04-17 03:01:36 -04:00
|
|
|
virtual FName GetIconName() const override
|
|
|
|
|
{
|
|
|
|
|
return FName("StateTreeEditorStyle|Node.RunParallel");
|
|
|
|
|
}
|
|
|
|
|
virtual FColor GetIconColor() const override
|
|
|
|
|
{
|
|
|
|
|
return UE::StateTree::Colors::Grey;
|
|
|
|
|
}
|
2024-03-20 08:28:58 -04:00
|
|
|
#endif // WITH_EDITOR
|
2024-04-03 07:16:44 -04:00
|
|
|
|
|
|
|
|
const FStateTreeReference& GetStateTreeToRun(FStateTreeExecutionContext& Context, FInstanceDataType& InstanceData) const;
|
|
|
|
|
|
|
|
|
|
/** If set the task will look at the linked state tree override to replace the state tree it's running. */
|
|
|
|
|
UPROPERTY(EditAnywhere, Category = Parameter)
|
|
|
|
|
FGameplayTag StateTreeOverrideTag;
|
2024-04-12 06:04:01 -04:00
|
|
|
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
/**
|
|
|
|
|
* At what priority the events should be handled in the parallel State Tree.
|
|
|
|
|
* If set to 'Normal' the order of the States in the State Tree will define the handling order.
|
|
|
|
|
* If the priority is set to Low, the main tree is let to handle the transitions first.
|
|
|
|
|
* If set to High or above, the parallel tree has change to handle events first.
|
|
|
|
|
* If multiple tasks has same priority, the State order of the States defines the handling order.
|
|
|
|
|
* The tree handling order is: States and handle from leaf to root, tasks before and handled before transitions per State.
|
|
|
|
|
*/
|
|
|
|
|
UPROPERTY(EditAnywhere, Category = Parameter)
|
|
|
|
|
EStateTreeTransitionPriority EventHandlingPriority = EStateTreeTransitionPriority::Normal;
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
2024-03-20 08:28:58 -04:00
|
|
|
};
|