2021-09-28 13:33:00 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "StateTreeTypes.h"
|
|
|
|
|
#include "StateTreeTaskBase.generated.h"
|
|
|
|
|
|
|
|
|
|
struct FStateTreeExecutionContext;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-21 04:53:16 -04:00
|
|
|
* Base struct for StateTree Tasks.
|
2021-09-28 13:33:00 -04:00
|
|
|
* Tasks are logic executed in an active state.
|
|
|
|
|
*/
|
|
|
|
|
USTRUCT()
|
2021-10-21 04:53:16 -04:00
|
|
|
struct STATETREEMODULE_API FStateTreeTaskBase
|
2021-09-28 13:33:00 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
2021-10-21 04:53:16 -04:00
|
|
|
FStateTreeTaskBase() = default;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-10-21 04:53:16 -04:00
|
|
|
virtual ~FStateTreeTaskBase() {}
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-12-01 03:42:52 -05:00
|
|
|
/** @return Struct that represents the runtime data of the task. */
|
2021-11-30 03:54:16 -05:00
|
|
|
virtual const UStruct* GetInstanceDataType() const { return nullptr; };
|
2021-11-12 05:49:31 -05:00
|
|
|
|
2021-10-27 06:11:44 -04:00
|
|
|
/**
|
|
|
|
|
* Called when the StateTree asset is linked. Allows to resolve references to other StateTree data.
|
2021-11-12 05:49:31 -05:00
|
|
|
* @see TStateTreeExternalDataHandle
|
|
|
|
|
* @see TStateTreeInstanceDataPropertyHandle
|
2021-10-27 06:11:44 -04:00
|
|
|
* @param Linker Reference to the linker
|
|
|
|
|
* @return true if linking succeeded.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool Link(FStateTreeLinker& Linker) { return true; }
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
/**
|
|
|
|
|
* Called when a new state is entered and task is part of active states. The change type parameter describes if the task's state
|
|
|
|
|
* was previously part of the list of active states (Sustained), or if it just became active (Changed).
|
|
|
|
|
* @param Context Reference to current execution context.
|
|
|
|
|
* @param ChangeType Describes the change type (Changed/Sustained).
|
|
|
|
|
* @param Transition Describes the states involved in the transition
|
|
|
|
|
* @return Succeed/Failed will end the state immediately and trigger to select new state, Running will carry on to tick the state.
|
|
|
|
|
*/
|
2021-11-12 05:49:31 -05:00
|
|
|
virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const EStateTreeStateChangeType ChangeType, const FStateTreeTransitionResult& Transition) const { return EStateTreeRunStatus::Running; }
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when a current state is exited and task is part of active states. The change type parameter describes if the task's state
|
|
|
|
|
* will be active after the transition (Sustained), or if it will became inactive (Changed).
|
|
|
|
|
* @param Context Reference to current execution context.
|
|
|
|
|
* @param ChangeType Describes the change type (Changed/Sustained).
|
|
|
|
|
* @param Transition Describes the states involved in the transition
|
|
|
|
|
*/
|
2021-11-12 05:49:31 -05:00
|
|
|
virtual void ExitState(FStateTreeExecutionContext& Context, const EStateTreeStateChangeType ChangeType, const FStateTreeTransitionResult& Transition) const {}
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called Right after a state has been completed. StateCompleted is called in reverse order to allow to propagate state to Evaluators and Tasks that
|
|
|
|
|
* are executed earlier in the tree. Note that StateCompleted is not called if conditional transition changes the state.
|
|
|
|
|
* @param Context Reference to current execution context.
|
|
|
|
|
* @param CompletionStatus Describes the running status of the completed state (Succeeded/Failed).
|
|
|
|
|
* @param CompletedState Handle of the state that was completed.
|
|
|
|
|
*/
|
2021-11-12 05:49:31 -05:00
|
|
|
virtual void StateCompleted(FStateTreeExecutionContext& Context, const EStateTreeRunStatus CompletionStatus, const FStateTreeHandle CompletedState) const {}
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
/**
|
2021-11-30 03:54:16 -05:00
|
|
|
* Called during state tree tick when the task is on active state.
|
|
|
|
|
* @param Context Reference to current execution context.
|
|
|
|
|
* @param DeltaTime Time since last StateTree tick.
|
|
|
|
|
* @return Running status of the state: Running if still in progress, Succeeded if execution is done and succeeded, Failed if execution is done and failed.
|
|
|
|
|
*/
|
2021-11-12 05:49:31 -05:00
|
|
|
virtual EStateTreeRunStatus Tick(FStateTreeExecutionContext& Context, const float DeltaTime) const { return EStateTreeRunStatus::Running; };
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
#if WITH_GAMEPLAY_DEBUGGER
|
|
|
|
|
virtual void AppendDebugInfoString(FString& DebugString, const FStateTreeExecutionContext& Context) const;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
UPROPERTY(EditAnywhere, Category = Task, meta = (EditCondition = "false", EditConditionHides))
|
|
|
|
|
FName Name;
|
|
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** Property binding copy batch handle. */
|
2021-09-28 13:33:00 -04:00
|
|
|
UPROPERTY()
|
2021-11-12 05:49:31 -05:00
|
|
|
FStateTreeHandle BindingsBatch = FStateTreeHandle::Invalid;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2021-11-12 05:49:31 -05:00
|
|
|
/** The runtime data's data view index in the StateTreeExecutionContext, and source struct index in property binding. */
|
2021-09-28 13:33:00 -04:00
|
|
|
UPROPERTY()
|
2021-11-12 05:49:31 -05:00
|
|
|
uint16 DataViewIndex = 0;
|
2021-11-24 04:26:29 -05:00
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
uint16 InstanceIndex = 0;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
uint8 bInstanceIsObject : 1;
|
2021-09-28 13:33:00 -04:00
|
|
|
};
|