2021-09-28 13:33:17 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
2022-02-03 09:13:49 -05:00
# include "StateTreeNodeBase.h"
2023-06-27 09:07:17 -04:00
# include "StateTreeExecutionTypes.h"
2021-09-28 13:33:17 -04:00
# include "StateTreeTaskBase.generated.h"
struct FStateTreeExecutionContext ;
/**
2021-10-21 04:51:39 -04:00
* Base struct for StateTree Tasks .
2021-09-28 13:33:17 -04:00
* Tasks are logic executed in an active state .
*/
2022-05-18 02:35:34 -04:00
USTRUCT ( meta = ( Hidden ) )
2022-02-03 09:13:49 -05:00
struct STATETREEMODULE_API FStateTreeTaskBase : public FStateTreeNodeBase
2021-09-28 13:33:17 -04:00
{
GENERATED_BODY ( )
2022-09-28 09:55:53 -04:00
FStateTreeTaskBase ( )
: bShouldStateChangeOnReselect ( true )
2022-11-01 15:11:19 -04:00
, bShouldCallTick ( true )
, bShouldCallTickOnlyOnEvents ( false )
, bShouldCopyBoundPropertiesOnTick ( true )
, bShouldCopyBoundPropertiesOnExitState ( true )
2023-01-23 12:48:04 -05:00
, bShouldAffectTransitions ( false )
2023-06-05 13:12:19 -04:00
, bTaskEnabled ( true )
2022-09-28 09:55:53 -04:00
{
}
2024-08-15 08:19:58 -04:00
UE_DEPRECATED ( 5.5 , " Use EnterState without the EStateTreeStateChangeType. " )
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 .
*/
virtual EStateTreeRunStatus EnterState ( FStateTreeExecutionContext & Context , const EStateTreeStateChangeType ChangeType , const FStateTreeTransitionResult & Transition ) const final { return EStateTreeRunStatus : : Running ; }
2024-08-15 08:19:58 -04:00
UE_DEPRECATED ( 5.5 , " Use ExitState without the EStateTreeStateChangeType. " )
/**
* 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-09-28 09:55:53 -04:00
virtual void ExitState ( FStateTreeExecutionContext & Context , const EStateTreeStateChangeType ChangeType , const FStateTreeTransitionResult & Transition ) const final { }
2021-09-28 13:33:17 -04:00
/**
2023-06-13 05:56:36 -04:00
* Called when a new state is entered and task is part of active states .
2021-09-28 13:33:17 -04:00
* @ param Context Reference to current execution context .
* @ 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 .
*/
2022-09-28 09:55:53 -04:00
virtual EStateTreeRunStatus EnterState ( FStateTreeExecutionContext & Context , const FStateTreeTransitionResult & Transition ) const { return EStateTreeRunStatus : : Running ; }
2021-09-28 13:33:17 -04:00
/**
2023-06-13 05:56:36 -04:00
* Called when a current state is exited and task is part of active states .
2021-09-28 13:33:17 -04:00
* @ param Context Reference to current execution context .
* @ param Transition Describes the states involved in the transition
*/
2022-09-28 09:55:53 -04:00
virtual void ExitState ( FStateTreeExecutionContext & Context , const FStateTreeTransitionResult & Transition ) const { }
2021-09-28 13:33:17 -04:00
/**
2023-06-13 05:56:36 -04:00
* Called right after a state has been completed , but before new state has been selected . StateCompleted is called in reverse order to allow to propagate state to other Tasks that
2021-09-28 13:33:17 -04:00
* 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 ) .
2022-04-05 03:20:57 -04:00
* @ param CompletedActiveStates Active states at the time of completion .
2021-09-28 13:33:17 -04:00
*/
2022-04-05 03:20:57 -04:00
virtual void StateCompleted ( FStateTreeExecutionContext & Context , const EStateTreeRunStatus CompletionStatus , const FStateTreeActiveStates & CompletedActiveStates ) const { }
2021-09-28 13:33:17 -04:00
/**
2021-11-30 03:53:20 -05:00
* Called during state tree tick when the task is on active state .
2023-01-23 12:48:04 -05:00
* Note : The method is called only if bShouldCallTick or bShouldCallTickOnlyOnEvents is set .
2021-11-30 03:53:20 -05:00
* @ 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:48:11 -05:00
virtual EStateTreeRunStatus Tick ( FStateTreeExecutionContext & Context , const float DeltaTime ) const { return EStateTreeRunStatus : : Running ; } ;
2021-09-28 13:33:17 -04:00
2023-01-23 12:48:04 -05:00
/**
* Called when state tree triggers transitions . This method is called during transition handling , before state ' s tick and event transitions are handled .
* Note : the method is called only if bShouldAffectTransitions is set .
* @ param Context Reference to current execution context .
*/
virtual void TriggerTransitions ( FStateTreeExecutionContext & Context ) const { } ;
2024-04-17 03:01:36 -04:00
# if WITH_EDITOR
virtual FName GetIconName ( ) const override
{
return FName ( " StateTreeEditorStyle|Node.Task " ) ;
}
virtual FColor GetIconColor ( ) const override
{
return UE : : StateTree : : Colors : : Grey ;
}
# endif
2023-01-23 12:48:04 -05:00
2021-09-28 13:33:17 -04:00
# if WITH_GAMEPLAY_DEBUGGER
virtual void AppendDebugInfoString ( FString & DebugString , const FStateTreeExecutionContext & Context ) const ;
# endif
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 .
* Default value is true . */
uint8 bShouldStateChangeOnReselect : 1 ;
2022-11-01 15:11:19 -04:00
2022-11-03 14:21:53 -04:00
/** If set to true, Tick() is called. Not ticking implies no property copy. Default true. */
2022-11-01 15:11:19 -04:00
uint8 bShouldCallTick : 1 ;
2022-11-03 14:21:53 -04:00
/** If set to true, Tick() is called only when there are events. No effect if bShouldCallTickState is true. Not ticking implies no property copy. Default false. */
2022-11-01 15:11:19 -04:00
uint8 bShouldCallTickOnlyOnEvents : 1 ;
/** If set to true, copy the values of bound properties before calling Tick(). Default true. */
uint8 bShouldCopyBoundPropertiesOnTick : 1 ;
/** If set to true, copy the values of bound properties before calling ExitState(). Default true. */
uint8 bShouldCopyBoundPropertiesOnExitState : 1 ;
2023-01-23 12:48:04 -05:00
/** If set to true, TriggerTransitions() is called during transition handling. Default false. */
uint8 bShouldAffectTransitions : 1 ;
2023-06-05 13:12:19 -04:00
/** True if the node is Enabled (i.e. not explicitly disabled in the asset). */
UPROPERTY ( )
uint8 bTaskEnabled : 1 ;
2024-04-12 06:04:01 -04:00
UPROPERTY ( )
EStateTreeTransitionPriority TransitionHandlingPriority = EStateTreeTransitionPriority : : Normal ;
2021-09-28 13:33:17 -04:00
} ;
2022-05-02 09:15:14 -04:00
/**
* Base class ( namespace ) for all common Tasks that are generally applicable .
* This allows schemas to safely include all conditions child of this struct .
*/
USTRUCT ( meta = ( Hidden ) )
struct STATETREEMODULE_API FStateTreeTaskCommonBase : public FStateTreeTaskBase
{
GENERATED_BODY ( )
} ;