2022-05-31 04:51:18 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
# include "StateTree.h"
2023-05-23 10:46:16 -04:00
# include "StateTreeExecutionTypes.h"
2022-06-29 04:52:18 -04:00
# include "StateTreeNodeBase.h"
2022-09-23 20:02:42 -04:00
# include "Experimental/ConcurrentLinearAllocator.h"
2022-05-31 04:51:18 -04:00
2023-01-25 02:42:36 -05:00
struct FGameplayTag ;
struct FInstancedPropertyBag ;
2022-05-31 04:51:18 -04:00
struct FStateTreeEvaluatorBase ;
struct FStateTreeTaskBase ;
struct FStateTreeConditionBase ;
2022-09-01 09:06:53 -04:00
struct FStateTreeEvent ;
2023-01-23 12:48:04 -05:00
struct FStateTreeTransitionRequest ;
2023-03-14 13:35:46 -04:00
struct FStateTreeInstanceDebugId ;
2022-05-31 04:51:18 -04:00
/**
2022-09-23 20:02:42 -04:00
* StateTree Execution Context is a helper that is used to update and access StateTree instance data .
*
* The context is meant to be temporary , you should not store a context across multiple frames .
*
* The owner is used as the owner of the instantiated UObjects in the instance data and logging , it should have same or greater lifetime as the InstanceData .
*
* In common case you can use the constructor or Init ( ) to initialize the context :
*
* FStateTreeExecutionContext Context ( * GetOwner ( ) , * StateTreeRef . GetStateTree ( ) , InstanceData ) ;
* if ( SetContextRequirements ( Context ) )
* {
* Context . Tick ( DeltaTime ) ;
* }
*
* bool UMyComponent : : SetContextRequirements ( FStateTreeExecutionContext & Context )
* {
* if ( ! Context . IsValid ( ) )
* {
* return false ;
* }
* // Setup context data
* return true ;
* }
2022-05-31 04:51:18 -04:00
*/
struct STATETREEMODULE_API FStateTreeExecutionContext
{
public :
2022-09-23 20:02:42 -04:00
FStateTreeExecutionContext ( UObject & InOwner , const UStateTree & InStateTree , FStateTreeInstanceData & InInstanceData ) ;
2022-05-31 04:51:18 -04:00
virtual ~ FStateTreeExecutionContext ( ) ;
/** Updates data view of the parameters by using the default values defined in the StateTree asset. */
void SetDefaultParameters ( ) ;
/**
* Updates data view of the parameters by replacing the default values defined in the StateTree asset by the provided values .
* Note : caller is responsible to make sure external parameters lifetime matches the context .
*/
void SetParameters ( const FInstancedPropertyBag & Parameters ) ;
2022-09-23 20:02:42 -04:00
/** @return the StateTree asset in use. */
const UStateTree * GetStateTree ( ) const { return & StateTree ; }
2022-05-31 04:51:18 -04:00
2022-11-01 15:11:19 -04:00
/** @return const references to the instance data in use, or nullptr if the context is not valid. */
2022-09-23 20:02:42 -04:00
const FStateTreeInstanceData * GetInstanceData ( ) const { return & InstanceData ; }
2022-05-31 04:51:18 -04:00
2022-11-01 15:11:19 -04:00
/** @retuen mutable references to the instance data in use, or nullptr if the context is not valid. */
2022-09-23 20:02:42 -04:00
FStateTreeInstanceData * GetMutableInstanceData ( ) const { return & InstanceData ; }
2022-11-01 15:11:19 -04:00
2022-11-30 07:17:26 -05:00
/** @return mutable references to the instance data in use. */
const FStateTreeEventQueue & GetEventQueue ( ) const { return InstanceData . GetEventQueue ( ) ; }
/** @return mutable references to the instance data in use. */
FStateTreeEventQueue & GetMutableEventQueue ( ) const { return InstanceData . GetMutableEventQueue ( ) ; }
2022-11-01 15:11:19 -04:00
2022-05-31 04:51:18 -04:00
/** @return The owner of the context */
2022-09-23 20:02:42 -04:00
UObject * GetOwner ( ) const { return & Owner ; }
2022-05-31 04:51:18 -04:00
/** @return The world of the owner or nullptr if the owner is not set. */
2022-09-23 20:02:42 -04:00
UWorld * GetWorld ( ) const { return Owner . GetWorld ( ) ; } ;
2022-05-31 04:51:18 -04:00
/** @return True of the the execution context is valid and initialized. */
2022-09-23 20:02:42 -04:00
bool IsValid ( ) const { return StateTree . IsReadyToRun ( ) ; }
2022-05-31 04:51:18 -04:00
/** Start executing. */
2022-09-23 20:02:42 -04:00
EStateTreeRunStatus Start ( ) ;
2023-06-05 06:33:07 -04:00
/**
* Stop executing if the tree is running .
* @ param CompletionStatus Status ( and terminal state ) reported in the transition when the tree is stopped .
* @ return Tree execution status at stop , can be CompletionStatus , or earlier status if the tree is not running .
*/
EStateTreeRunStatus Stop ( const EStateTreeRunStatus CompletionStatus = EStateTreeRunStatus : : Stopped ) ;
2022-05-31 04:51:18 -04:00
2022-12-16 05:45:13 -05:00
/**
* Tick the state tree logic .
* @ param DeltaTime time to advance the logic .
* @ returns tree run status after the tick .
*/
2022-09-23 20:02:42 -04:00
EStateTreeRunStatus Tick ( const float DeltaTime ) ;
2022-05-31 04:51:18 -04:00
2022-12-16 05:45:13 -05:00
/** @return the tree run status. */
EStateTreeRunStatus GetStateTreeRunStatus ( ) const ;
2022-09-01 09:06:53 -04:00
/** @return the status of the last tick function */
2022-09-23 20:02:42 -04:00
EStateTreeRunStatus GetLastTickStatus ( ) const ;
2022-09-01 09:06:53 -04:00
/** @return reference to the list of currently active states. */
2022-09-23 20:02:42 -04:00
const FStateTreeActiveStates & GetActiveStates ( ) const ;
2022-09-01 09:06:53 -04:00
# if WITH_GAMEPLAY_DEBUGGER
/** @return Debug string describing the current state of the execution */
2022-09-23 20:02:42 -04:00
FString GetDebugInfoString ( ) const ;
2022-09-01 09:06:53 -04:00
# endif // WITH_GAMEPLAY_DEBUGGER
# if WITH_STATETREE_DEBUG
2022-09-23 20:02:42 -04:00
int32 GetStateChangeCount ( ) const ;
2022-09-01 09:06:53 -04:00
2022-09-23 20:02:42 -04:00
void DebugPrintInternalLayout ( ) ;
2022-09-01 09:06:53 -04:00
# endif
/** @return the name of the active state. */
2022-09-23 20:02:42 -04:00
FString GetActiveStateName ( ) const ;
2022-09-01 09:06:53 -04:00
/** @return the names of all the active state. */
2022-09-23 20:02:42 -04:00
TArray < FName > GetActiveStateNames ( ) const ;
2022-09-01 09:06:53 -04:00
2022-09-30 12:21:42 -04:00
/** Sends event for the StateTree. */
2022-11-03 14:21:53 -04:00
UE_DEPRECATED ( 5.2 , " Use AddEvent() with individual parameters instead. " )
2022-11-01 15:11:19 -04:00
void SendEvent ( const FStateTreeEvent & Event ) const ;
/** Sends event for the StateTree. */
void SendEvent ( const FGameplayTag Tag , const FConstStructView Payload = FConstStructView ( ) , const FName Origin = FName ( ) ) const ;
2022-09-01 09:06:53 -04:00
/** Iterates over all events. Can only be used during StateTree tick. Expects a lambda which takes const FStateTreeEvent& Event, and returns EStateTreeLoopEvents. */
template < typename TFunc >
void ForEachEvent ( TFunc & & Function ) const
{
for ( const FStateTreeEvent & Event : EventsToProcess )
{
if ( Function ( Event ) = = EStateTreeLoopEvents : : Break )
{
break ;
}
}
}
/** @return events to process this tick. */
TConstArrayView < FStateTreeEvent > GetEventsToProcess ( ) const { return EventsToProcess ; }
2023-01-23 12:48:04 -05:00
/** @return true if there is a pending event with specified tag. */
bool HasEventToProcess ( const FGameplayTag Tag ) const
{
if ( EventsToProcess . IsEmpty ( ) )
{
return false ;
}
return EventsToProcess . ContainsByPredicate ( [ Tag ] ( const FStateTreeEvent & Event )
{
return Event . Tag . MatchesTag ( Tag ) ;
} ) ;
}
/** @return the currently processed state if applicable. */
FStateTreeStateHandle GetCurrentlyProcessedState ( ) const { return CurrentlyProcessedState ; }
2022-09-01 09:06:53 -04:00
2022-05-31 04:51:18 -04:00
/** @return Pointer to a State or null if state not found */
const FCompactStateTreeState * GetStateFromHandle ( const FStateTreeStateHandle StateHandle ) const
{
2023-03-14 13:35:46 -04:00
return StateTree . GetStateFromHandle ( StateHandle ) ;
2022-05-31 04:51:18 -04:00
}
/** @return Array view to external data descriptors associated with this context. Note: Init() must be called before calling this method. */
TConstArrayView < FStateTreeExternalDataDesc > GetExternalDataDescs ( ) const
{
2022-09-23 20:02:42 -04:00
return StateTree . ExternalDataDescs ;
2022-05-31 04:51:18 -04:00
}
/** @return Array view to named external data descriptors associated with this context. Note: Init() must be called before calling this method. */
2022-09-19 19:47:11 -04:00
TConstArrayView < FStateTreeExternalDataDesc > GetContextDataDescs ( ) const
2022-05-31 04:51:18 -04:00
{
2022-09-23 20:02:42 -04:00
return StateTree . GetContextDataDescs ( ) ;
2022-05-31 04:51:18 -04:00
}
/** @return True if all required external data pointers are set. */
2022-09-01 09:06:53 -04:00
bool AreExternalDataViewsValid ( ) const ;
2022-05-31 04:51:18 -04:00
/** @return Handle to external data of type InStruct, or invalid handle if struct not found. */
FStateTreeExternalDataHandle GetExternalDataHandleByStruct ( const UStruct * InStruct ) const
{
2022-09-23 20:02:42 -04:00
const FStateTreeExternalDataDesc * DataDesc = StateTree . ExternalDataDescs . FindByPredicate ( [ InStruct ] ( const FStateTreeExternalDataDesc & Item ) { return Item . Struct = = InStruct ; } ) ;
2022-05-31 04:51:18 -04:00
return DataDesc ! = nullptr ? DataDesc - > Handle : FStateTreeExternalDataHandle : : Invalid ;
}
/** Sets external data view value for specific item. */
void SetExternalData ( const FStateTreeExternalDataHandle Handle , FStateTreeDataView DataView )
{
check ( Handle . IsValid ( ) ) ;
DataViews [ Handle . DataViewIndex . Get ( ) ] = DataView ;
}
/**
* Returns reference to external data based on provided handle . The return type is deduced from the handle ' s template type .
* @ param Handle Valid TStateTreeExternalDataHandle < > handle .
* @ return reference to external data based on handle or null if data is not set .
*/
template < typename T >
typename T : : DataType & GetExternalData ( const T Handle ) const
{
check ( Handle . IsValid ( ) ) ;
2022-09-23 20:02:42 -04:00
checkSlow ( StateTree . ExternalDataDescs [ Handle . DataViewIndex . Get ( ) - StateTree . ExternalDataBaseIndex ] . Requirement ! = EStateTreeExternalDataRequirement : : Optional ) ; // Optionals should query pointer instead.
2022-05-31 04:51:18 -04:00
return DataViews [ Handle . DataViewIndex . Get ( ) ] . template GetMutable < typename T : : DataType > ( ) ;
}
/**
* Returns pointer to external data based on provided item handle . The return type is deduced from the handle ' s template type .
* @ param Handle Valid TStateTreeExternalDataHandle < > handle .
* @ return pointer to external data based on handle or null if item is not set or handle is invalid .
*/
template < typename T >
typename T : : DataType * GetExternalDataPtr ( const T Handle ) const
{
return Handle . IsValid ( ) ? DataViews [ Handle . DataViewIndex . Get ( ) ] . template GetMutablePtr < typename T : : DataType > ( ) : nullptr ;
}
FStateTreeDataView GetExternalDataView ( const FStateTreeExternalDataHandle Handle )
{
if ( Handle . IsValid ( ) )
{
return DataViews [ Handle . DataViewIndex . Get ( ) ] ;
}
return FStateTreeDataView ( ) ;
}
2022-06-29 04:52:18 -04:00
/** @returns pointer to the instance data of specified node. */
template < typename T >
T * GetInstanceDataPtr ( const FStateTreeNodeBase & Node ) const
{
return DataViews [ Node . DataViewIndex . Get ( ) ] . template GetMutablePtr < T > ( ) ;
}
/** @returns reference to the instance data of specified node. */
template < typename T >
T & GetInstanceData ( const FStateTreeNodeBase & Node ) const
{
return DataViews [ Node . DataViewIndex . Get ( ) ] . template GetMutable < T > ( ) ;
}
2022-09-29 20:26:53 -04:00
/** @returns reference to the instance data of specified node. Infers the instance data type from the node's FInstanceDataType. */
template < typename T >
typename T : : FInstanceDataType & GetInstanceData ( const T & Node ) const
{
static_assert ( TIsDerivedFrom < T , FStateTreeNodeBase > : : IsDerived , " Expecting Node to derive from FStateTreeNodeBase. " ) ;
return DataViews [ Node . DataViewIndex . Get ( ) ] . template GetMutable < typename T : : FInstanceDataType > ( ) ;
}
2022-11-01 15:11:19 -04:00
/** @returns reference to instance data struct that can be passed to lambdas. See TStateTreeInstanceDataStructRef for usage. */
template < typename T >
TStateTreeInstanceDataStructRef < typename T : : FInstanceDataType > GetInstanceDataStructRef ( const T & Node ) const
{
static_assert ( TIsDerivedFrom < T , FStateTreeNodeBase > : : IsDerived , " Expecting Node to derive from FStateTreeNodeBase. " ) ;
return TStateTreeInstanceDataStructRef < typename T : : FInstanceDataType > ( InstanceData , DataViews [ Node . DataViewIndex . Get ( ) ] . template GetMutable < typename T : : FInstanceDataType > ( ) ) ;
}
2023-01-23 12:48:04 -05:00
/**
* Requests transition to a state .
* If called during during transition processing ( e . g . from FStateTreeTaskBase : : TriggerTransitions ( ) ) the transition
* is attempted to be activate immediately ( it can fail e . g . because of preconditions on a target state ) .
* If called outside the transition handling , the request is buffered and handled at the beginning of next transition processing .
* @ param Request The state to transition to .
*/
void RequestTransition ( const FStateTreeTransitionRequest & Request ) ;
2022-05-31 04:51:18 -04:00
protected :
2023-03-14 13:35:46 -04:00
# if WITH_STATETREE_DEBUGGER
FStateTreeInstanceDebugId GetInstanceDebugId ( ) const ;
# endif // WITH_STATETREE_DEBUGGER
/** @return Prefix that will be used by STATETREE_LOG and STATETREE_CLOG, Owner name by default. */
2022-05-31 04:51:18 -04:00
virtual FString GetInstanceDescription ( ) const ;
2022-12-02 07:57:31 -05:00
UE_DEPRECATED ( 5.2 , " Use BeginDelayedTransition() instead. " )
virtual void BeginGatedTransition ( const FStateTreeExecutionState & Exec ) final { } ;
/** Callback when delayed transition is triggered. Contexts that are event based can use this to trigger a future event. */
virtual void BeginDelayedTransition ( const FStateTreeTransitionDelayedState & DelayedState ) { } ;
2022-05-31 04:51:18 -04:00
2022-09-23 20:02:42 -04:00
void UpdateInstanceData ( const FStateTreeActiveStates & CurrentActiveStates , const FStateTreeActiveStates & NextActiveStates ) ;
2022-05-31 04:51:18 -04:00
/**
* Handles logic for entering State . EnterState is called on new active Evaluators and Tasks that are part of the re - planned tree .
* Re - planned tree is from the transition target up to the leaf state . States that are parent to the transition target state
* and still active after the transition will remain intact .
* @ return Run status returned by the tasks .
*/
2022-09-23 20:02:42 -04:00
EStateTreeRunStatus EnterState ( const FStateTreeTransitionResult & Transition ) ;
2022-05-31 04:51:18 -04:00
/**
* Handles logic for exiting State . ExitState is called on current active Evaluators and Tasks that are part of the re - planned tree .
* Re - planned tree is from the transition target up to the leaf state . States that are parent to the transition target state
* and still active after the transition will remain intact .
*/
2022-09-23 20:02:42 -04:00
void ExitState ( const FStateTreeTransitionResult & Transition ) ;
2022-05-31 04:51:18 -04:00
/**
* Handles logic for signalling State completed . StateCompleted is called on current active Evaluators and Tasks in reverse order ( from leaf to root ) .
*/
2022-09-23 20:02:42 -04:00
void StateCompleted ( ) ;
2022-05-31 04:51:18 -04:00
/**
2023-01-10 15:44:28 -05:00
* Tick evaluators and global tasks by delta time .
2022-05-31 04:51:18 -04:00
*/
2023-01-10 15:44:28 -05:00
EStateTreeRunStatus TickEvaluatorsAndGlobalTasks ( const float DeltaTime , bool bTickGlobalTasks = true ) ;
2022-05-31 04:51:18 -04:00
2023-01-10 15:44:28 -05:00
/**
* Starts evaluators and global tasks .
2023-06-05 06:33:07 -04:00
* @ return run status returned by the global tasks .
2023-01-10 15:44:28 -05:00
*/
2023-06-05 06:33:07 -04:00
EStateTreeRunStatus StartEvaluatorsAndGlobalTasks ( FStateTreeIndex16 & OutLastInitializedTaskIndex ) ;
2022-05-31 04:51:18 -04:00
2023-01-10 15:44:28 -05:00
/**
* Stops evaluators and global tasks .
*/
2023-06-05 06:33:07 -04:00
void StopEvaluatorsAndGlobalTasks ( const EStateTreeRunStatus CompletionStatus , const FStateTreeIndex16 LastInitializedTaskIndex = FStateTreeIndex16 ( ) ) ;
2022-05-31 04:51:18 -04:00
/**
* Ticks tasks of all active states starting from current state by delta time .
* @ return Run status returned by the tasks .
*/
2022-09-23 20:02:42 -04:00
EStateTreeRunStatus TickTasks ( const float DeltaTime ) ;
2022-05-31 04:51:18 -04:00
/**
* Checks all conditions at given range
* @ return True if all conditions pass .
*/
2023-01-23 12:48:04 -05:00
bool TestAllConditions ( const int32 ConditionsOffset , const int32 ConditionsNum ) ;
2022-05-31 04:51:18 -04:00
2022-12-02 07:57:31 -05:00
/**
2023-01-23 12:48:04 -05:00
* Requests transition to a specified state with specified priority .
2022-12-02 07:57:31 -05:00
*/
2023-01-23 12:48:04 -05:00
bool RequestTransition ( const FStateTreeStateHandle NextState , const EStateTreeTransitionPriority Priority ) ;
2022-12-02 07:57:31 -05:00
2022-05-31 04:51:18 -04:00
/**
* Triggers transitions based on current run status . CurrentStatus is used to select which transitions events are triggered .
* If CurrentStatus is " Running " , " Conditional " transitions pass , " Completed/Failed " will trigger " OnCompleted/OnSucceeded/OnFailed " transitions .
* Transition target state can point to a selector state . For that reason the result contains both the target state , as well ass
* the actual next state returned by the selector .
* @ return Transition result describing the source state , state transitioned to , and next selected state .
*/
2023-01-23 12:48:04 -05:00
bool TriggerTransitions ( ) ;
2022-05-31 04:51:18 -04:00
2022-11-23 09:22:14 -05:00
/**
* Traverses the ActiveStates from StartStateIndex to 0 and returns first linked state .
* @ return Parent linked state , or invalid state if no linked state found .
*/
FStateTreeStateHandle GetParentLinkedStateHandle ( const FStateTreeActiveStates & ActiveStates , const int32 StartStateIndex ) const ;
2023-01-23 12:48:04 -05:00
FStateTreeStateHandle GetParentLinkedStateHandle ( const FStateTreeActiveStates & ActiveStates , const FStateTreeStateHandle StartStateHandle ) const ;
2022-05-31 04:51:18 -04:00
/**
* Runs state selection logic starting at the specified state , walking towards the leaf states .
* If a state cannot be selected , false is returned .
* If NextState is a selector state , SelectStateInternal is called recursively ( depth - first ) to all child states ( where NextState will be one of child states ) .
* If NextState is a leaf state , the active states leading from root to the leaf are returned .
* @ param NextState The state which we try to select next .
* @ param OutNewActiveStates Active states that got selected .
2023-04-12 07:59:16 -04:00
* @ param VisitedStates States visited so far during selection ( used for detecting selection loops )
2022-05-31 04:51:18 -04:00
* @ return True if succeeded to select new active states .
*/
2023-04-12 07:59:16 -04:00
bool SelectState ( const FStateTreeStateHandle NextState , FStateTreeActiveStates & OutNewActiveStates , FStateTreeActiveStates & VisitedStates ) ;
2022-05-31 04:51:18 -04:00
/**
* Used internally to do the recursive part of the SelectState ( ) .
*/
2023-04-12 07:59:16 -04:00
bool SelectStateInternal ( const FStateTreeStateHandle NextState , FStateTreeActiveStates & OutNewActiveStates , FStateTreeActiveStates & VisitedStates ) ;
2022-05-31 04:51:18 -04:00
/** @return StateTree execution state from the instance storage. */
2022-09-23 20:02:42 -04:00
FStateTreeExecutionState & GetExecState ( )
2022-05-31 04:51:18 -04:00
{
2023-02-13 20:06:02 -05:00
return InstanceData . GetMutableStruct ( 0 ) . Get < FStateTreeExecutionState > ( ) ;
2022-05-31 04:51:18 -04:00
}
/** @return const StateTree execution state from the instance storage. */
2022-09-23 20:02:42 -04:00
const FStateTreeExecutionState & GetExecState ( ) const
2022-05-31 04:51:18 -04:00
{
2023-02-13 20:06:02 -05:00
return InstanceData . GetStruct ( 0 ) . Get < const FStateTreeExecutionState > ( ) ;
2022-05-31 04:51:18 -04:00
}
/** Sets up parameter data view for a linked state and copies bound properties. */
2022-12-02 10:07:29 -05:00
void UpdateLinkedStateParameters ( const FCompactStateTreeState & State , const int32 ParameterInstanceIndex ) ;
2022-05-31 04:51:18 -04:00
/** Sets up parameter data view for subtree state. */
2022-09-23 20:02:42 -04:00
void UpdateSubtreeStateParameters ( const FCompactStateTreeState & State ) ;
2022-05-31 04:51:18 -04:00
/** @return String describing state status for logging and debug. */
FString GetStateStatusString ( const FStateTreeExecutionState & ExecState ) const ;
/** @return String describing state name for logging and debug. */
FString GetSafeStateName ( const FStateTreeStateHandle State ) const ;
/** @return String describing full path of an activate state for logging and debug. */
2022-11-03 14:21:53 -04:00
FString DebugGetStatePath ( const FStateTreeActiveStates & ActiveStates , const int32 ActiveStateIndex = INDEX_NONE ) const ;
2022-05-31 04:51:18 -04:00
2022-11-01 15:11:19 -04:00
/** @return String describing all events that are currently being processed for logging and debug. */
FString DebugGetEventsAsString ( ) const ;
2022-09-23 20:02:42 -04:00
/** Helper function to update struct or object dataview of a node. */
template < typename T >
void SetNodeDataView ( T & Node , int32 & InstanceStructIndex , int32 & InstanceObjectIndex )
2022-09-01 09:06:53 -04:00
{
2022-09-23 20:02:42 -04:00
if ( Node . bInstanceIsObject )
2022-09-01 09:06:53 -04:00
{
2022-09-23 20:02:42 -04:00
DataViews [ Node . DataViewIndex . Get ( ) ] = InstanceData . GetMutableObject ( InstanceObjectIndex ) ;
InstanceObjectIndex + + ;
2022-09-01 09:06:53 -04:00
}
2022-09-23 20:02:42 -04:00
else
2022-09-01 09:06:53 -04:00
{
2022-09-23 20:02:42 -04:00
DataViews [ Node . DataViewIndex . Get ( ) ] = InstanceData . GetMutableStruct ( InstanceStructIndex ) ;
InstanceStructIndex + + ;
2022-09-01 09:06:53 -04:00
}
2022-09-23 20:02:42 -04:00
}
2022-09-01 09:06:53 -04:00
2022-09-23 20:02:42 -04:00
/** Owner of the instance data. */
UObject & Owner ;
2022-05-31 04:51:18 -04:00
/** The StateTree asset the context is initialized for */
2022-09-23 20:02:42 -04:00
const UStateTree & StateTree ;
2022-05-31 04:51:18 -04:00
2022-09-01 09:06:53 -04:00
/** Instance data used during current tick. */
2022-09-23 20:02:42 -04:00
FStateTreeInstanceData & InstanceData ;
2022-09-01 09:06:53 -04:00
2022-05-31 04:51:18 -04:00
/** Array of data pointers (external data, tasks, evaluators, conditions), used during evaluation. Initialized to match the number of items in the asset. */
2022-09-23 20:02:42 -04:00
TArray < FStateTreeDataView , TConcurrentLinearArrayAllocator < FDefaultBlockAllocationTag > > DataViews ;
2022-09-01 09:06:53 -04:00
/** Events to process in current tick. */
2022-09-23 20:02:42 -04:00
TArray < FStateTreeEvent , TConcurrentLinearArrayAllocator < FDefaultBlockAllocationTag > > EventsToProcess ;
2023-01-23 12:48:04 -05:00
/** Shared instance data for the duration of the context. */
TSharedPtr < FStateTreeInstanceData > SharedInstanceData ;
/** Next transition, used by RequestTransition(). */
FStateTreeTransitionResult NextTransition ;
2023-08-04 14:23:12 -04:00
/** Structure describing the origin of the state transition that caused the state change. */
FStateTreeTransitionSource NextTransitionSource ;
2023-06-21 10:02:02 -04:00
2023-01-23 12:48:04 -05:00
/** Current state we're processing, or invalid if not applicable. */
FStateTreeStateHandle CurrentlyProcessedState ;
/** True if transitions are allowed to be requested directly instead of buffering. */
bool bAllowDirectTransitions = false ;
/** Helper struct to track when it is allowed to request transitions. */
struct FAllowDirectTransitionsScope
{
FAllowDirectTransitionsScope ( FStateTreeExecutionContext & InContext )
: Context ( InContext )
{
Context . bAllowDirectTransitions = true ;
}
~ FAllowDirectTransitionsScope ( )
{
Context . bAllowDirectTransitions = false ;
}
FStateTreeExecutionContext & Context ;
} ;
/** Helper struct to track currently processed state. */
struct FCurrentlyProcessedStateScope
{
FCurrentlyProcessedStateScope ( FStateTreeExecutionContext & InContext , const FStateTreeStateHandle State )
: Context ( InContext )
{
Context . CurrentlyProcessedState = State ;
}
~ FCurrentlyProcessedStateScope ( )
{
Context . CurrentlyProcessedState = FStateTreeStateHandle : : Invalid ;
}
FStateTreeExecutionContext & Context ;
} ;
2022-05-31 04:51:18 -04:00
} ;