2023-01-25 02:42:36 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2021-11-24 04:26:12 -05:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-11-25 02:39:02 -05:00
|
|
|
#include "Templates/SubclassOf.h"
|
2021-11-24 04:26:12 -05:00
|
|
|
#include "StateTreeTaskBase.h"
|
2022-09-01 09:06:53 -04:00
|
|
|
#include "StateTreeNodeBlueprintBase.h"
|
2021-11-24 04:26:12 -05:00
|
|
|
#include "StateTreeTaskBlueprintBase.generated.h"
|
|
|
|
|
|
|
|
|
|
struct FStateTreeExecutionContext;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Base class for Blueprint based Tasks.
|
|
|
|
|
*/
|
|
|
|
|
UCLASS(Abstract, Blueprintable)
|
2022-09-01 09:06:53 -04:00
|
|
|
class STATETREEMODULE_API UStateTreeTaskBlueprintBase : public UStateTreeNodeBlueprintBase
|
2021-11-24 04:26:12 -05:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
public:
|
2022-09-19 19:47:11 -04:00
|
|
|
UStateTreeTaskBlueprintBase(const FObjectInitializer& ObjectInitializer);
|
2021-11-24 04:26:12 -05:00
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "EnterState"))
|
2022-09-28 09:55:53 -04:00
|
|
|
EStateTreeRunStatus ReceiveEnterState(const FStateTreeTransitionResult& Transition);
|
2021-11-24 04:26:12 -05:00
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "ExitState"))
|
2022-09-28 09:55:53 -04:00
|
|
|
void ReceiveExitState(const FStateTreeTransitionResult& Transition);
|
2021-11-24 04:26:12 -05:00
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "StateCompleted"))
|
2022-09-19 19:47:11 -04:00
|
|
|
void ReceiveStateCompleted(const EStateTreeRunStatus CompletionStatus, const FStateTreeActiveStates CompletedActiveStates);
|
2021-11-24 04:26:12 -05:00
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Tick"))
|
2022-09-19 19:47:11 -04:00
|
|
|
EStateTreeRunStatus ReceiveTick(const float DeltaTime);
|
2021-11-24 04:26:12 -05:00
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
protected:
|
2022-09-28 09:55:53 -04:00
|
|
|
/**
|
|
|
|
|
* Note: The API has been deprecated. ChangeType is moved into FStateTreeTransitionResult.
|
|
|
|
|
* You can configure the task to be only called on state changes (that is, never call sustained changes) by setting bShouldStateChangeOnReselect to true.
|
|
|
|
|
*/
|
2022-11-01 15:11:19 -04:00
|
|
|
UE_DEPRECATED(5.2, "Use EnterState without ChangeType instead.")
|
2022-09-28 09:55:53 -04:00
|
|
|
virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const EStateTreeStateChangeType ChangeType, const FStateTreeTransitionResult& Transition) final { return EStateTreeRunStatus::Running; }
|
2022-11-01 15:11:19 -04:00
|
|
|
UE_DEPRECATED(5.2, "Use ExitState without ChangeType instead.")
|
2022-09-28 09:55:53 -04:00
|
|
|
virtual void ExitState(FStateTreeExecutionContext& Context, const EStateTreeStateChangeType ChangeType, const FStateTreeTransitionResult& Transition) final {};
|
|
|
|
|
|
|
|
|
|
virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition);
|
|
|
|
|
virtual void ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition);
|
|
|
|
|
|
2022-04-05 03:20:57 -04:00
|
|
|
virtual void StateCompleted(FStateTreeExecutionContext& Context, const EStateTreeRunStatus CompletionStatus, const FStateTreeActiveStates& CompletedActiveStates);
|
2021-11-24 04:26:12 -05:00
|
|
|
virtual EStateTreeRunStatus Tick(FStateTreeExecutionContext& Context, const float DeltaTime);
|
2022-09-19 19:47:11 -04:00
|
|
|
|
2022-09-28 09:55:53 -04:00
|
|
|
/**
|
|
|
|
|
* If set to true, the task will receive EnterState/ExitState even if the state was previously active.
|
|
|
|
|
* Generally this should be true for action type tasks, like playing animation,
|
|
|
|
|
* and false on state like tasks like claiming a resource that is expected to be acquired on child states. */
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category="Default")
|
2022-11-01 15:11:19 -04:00
|
|
|
uint8 bShouldStateChangeOnReselect : 1;
|
|
|
|
|
|
2022-11-22 06:18:24 -05:00
|
|
|
/**
|
|
|
|
|
* If set to true, Tick() is called. Not ticking implies no property copy. Default true.
|
|
|
|
|
* Note: this is intentionally not a property, should be only set by C++ derived classes when the tick should not be called.
|
|
|
|
|
*/
|
|
|
|
|
uint8 bShouldCallTick : 1;
|
|
|
|
|
|
2022-11-01 15:11:19 -04:00
|
|
|
/** If set to true, Tick() is called. Default false. */
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category="Default")
|
|
|
|
|
uint8 bShouldCallTickOnlyOnEvents : 1;
|
2022-09-28 09:55:53 -04:00
|
|
|
|
2022-11-18 08:38:31 -05:00
|
|
|
/** If set to true, copy the values of bound properties before calling Tick(). Default true. */
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category="Default")
|
|
|
|
|
uint8 bShouldCopyBoundPropertiesOnTick : 1;
|
|
|
|
|
|
|
|
|
|
/** If set to true, copy the values of bound properties before calling ExitState(). Default true. */
|
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category="Default")
|
|
|
|
|
uint8 bShouldCopyBoundPropertiesOnExitState : 1;
|
|
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
uint8 bHasEnterState : 1;
|
|
|
|
|
uint8 bHasExitState : 1;
|
|
|
|
|
uint8 bHasStateCompleted : 1;
|
|
|
|
|
uint8 bHasTick : 1;
|
|
|
|
|
|
|
|
|
|
friend struct FStateTreeBlueprintTaskWrapper;
|
2021-11-24 04:26:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wrapper for Blueprint based Tasks.
|
|
|
|
|
*/
|
|
|
|
|
USTRUCT()
|
|
|
|
|
struct STATETREEMODULE_API FStateTreeBlueprintTaskWrapper : public FStateTreeTaskBase
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
virtual const UStruct* GetInstanceDataType() const override { return TaskClass; };
|
2022-11-18 08:38:31 -05:00
|
|
|
virtual EDataValidationResult Compile(FStateTreeDataView InstanceDataView, TArray<FText>& ValidationMessages) override;
|
2022-09-28 09:55:53 -04:00
|
|
|
virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
|
|
|
|
|
virtual void ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
|
2022-04-05 03:20:57 -04:00
|
|
|
virtual void StateCompleted(FStateTreeExecutionContext& Context, const EStateTreeRunStatus CompletionStatus, const FStateTreeActiveStates& CompletedActiveStates) const override;
|
2021-11-24 04:26:12 -05:00
|
|
|
virtual EStateTreeRunStatus Tick(FStateTreeExecutionContext& Context, const float DeltaTime) const override;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TSubclassOf<UStateTreeTaskBlueprintBase> TaskClass = nullptr;
|
|
|
|
|
};
|
2023-01-25 02:42:36 -05:00
|
|
|
|
|
|
|
|
#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_2
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "StateTreeEvents.h"
|
|
|
|
|
#endif
|