Navigation
API > API/Plugins > API/Plugins/StateTreeModule
Inheritance Hierarchy
- FStateTreeExecutionContext
- FMassStateTreeExecutionContext
References
| Module | StateTreeModule |
| Header | /Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Public/StateTreeExecutionContext.h |
| Include | #include "StateTreeExecutionContext.h" |
Syntax
struct FStateTreeExecutionContext
Remarks
StateTree Execution Context is a helper that is used to update 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 to initialize the context, and us a helper struct to set up the context data and external data getter: 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 Context.SetContextDataByName(...); ...
Context.SetCollectExternalDataCallback(FOnCollectStateTreeExternalData::CreateUObject(this, &UMyComponent::CollectExternalData);
return Context.AreContextDataViewsValid(); }
bool UMyComponent::CollectExternalData(const FStateTreeExecutionContext& Context, const UStateTree* StateTree, TArrayView
In this example the SetContextRequirements() method is used to set the context defined in the schema, and the delegate FOnCollectStateTreeExternalData is used to query the external data required by the tasks and conditions.
In case the State Tree links to other state tree assets, the collect external data might get called multiple times, once for each asset.
Variables
| Type | Name | Description | |
|---|---|---|---|
| bool | bActiveExternalDataCollected | ||
| bool | bAllowDirectTransitions | True if transitions are allowed to be requested directly instead of buffering. | |
| TArray< FCollectedExternalDataCache, TConcurrentLinearArrayAllocator< FDefaultBlockAllocationTag > > | CollectedExternalCache | ||
| FOnCollectStateTreeExternalData | CollectExternalDataDelegate | ||
| TArray< FStateTreeDataView, TConcurrentLinearArrayAllocator< FDefaultBlockAllocationTag > > | ContextAndExternalDataViews | Data view of the context data. | |
| const FStateTreeExecutionFrame * | CurrentlyProcessedFrame | ||
| const FStateTreeExecutionFrame * | CurrentlyProcessedParentFrame | Current frame we're processing. | |
| FStateTreeInstanceStorage * | CurrentlyProcessedSharedInstanceStorage | Pointer to the shared instance data of the current frame we're processing. | |
| FStateTreeStateHandle | CurrentlyProcessedState | Current state we're processing, or invalid if not applicable. | |
| FStateTreeDataHandle | CurrentNodeDataHandle | Currently processed nodes instance data. | |
| FStateTreeDataView | CurrentNodeInstanceData | ||
| TArray< FStateTreeEvent, TConcurrentLinearArrayAllocator< FDefaultBlockAllocationTag > > | EventsToProcess | Events to process in current tick. | |
| FStateTreeInstanceData & | InstanceData | Instance data used during current tick. | |
| FStateTreeInstanceStorage * | InstanceDataStorage | Data storage of the instance data, cached for less indirections. | |
| FStateTreeTransitionResult | NextTransition | Next transition, used by RequestTransition(). | |
| FStateTreeTransitionSource | NextTransitionSource | Structure describing the origin of the state transition that caused the state change. | |
| UObject & | Owner | Owner of the instance data. | |
| const UStateTree & | RootStateTree | The StateTree asset the context is initialized for |
Constructors
| Type | Name | Description | |
|---|---|---|---|
FStateTreeExecutionContext
(
UObject& InOwner, |
Destructors
| Type | Name | Description | |
|---|---|---|---|
Functions
| Type | Name | Description | |
|---|---|---|---|
| FStateTreeDataView | AddTemporaryInstance
(
const FStateTreeExecutionFrame& Frame, |
Adds a temporary instance that can be located using frame and data handle later. | |
| bool | |||
| bool | |||
| void | BeginDelayedTransition
(
const FStateTreeTransitionDelayedState& DelayedState |
Callback when delayed transition is triggered. | |
| bool | Collects external data for all StateTrees in active frames. | ||
| FStateTreeIndex16 | CollectExternalData
(
const UStateTree* StateTree |
Collects external data for specific State Tree asset. | |
| bool | CopyBatchOnActiveInstances
(
const FStateTreeExecutionFrame* ParentFrame, |
Copies a batch of properties to the data in TargetView. | |
| bool | CopyBatchWithValidation
(
const FStateTreeExecutionFrame* ParentFrame, |
Copies a batch of properties to the data in TargetView. | |
| FString | |||
| FString | DebugGetStatePath
(
TConstArrayView< FStateTreeExecutionFrame > ActiveFrames, |
||
| void | |||
| EStateTreeRunStatus | EnterState
(
FStateTreeTransitionResult& Transition |
Handles logic for entering State. | |
| void | ExitState
(
const FStateTreeTransitionResult& Transition |
Handles logic for exiting State. | |
| void | ForEachEvent
(
TFunc&& Function |
Iterates over all events. | |
| TConstArrayView< FStateTreeExecutionFrame > | |||
| FString | |||
| TArray< FName > | |||
| const FStateTreeActiveStates & | |||
| TConstArrayView< FStateTreeExternalDataDesc > | |||
| const FStateTreeExecutionFrame * | |||
| const FStateTreeExecutionFrame * | |||
| FStateTreeStateHandle | |||
| FStateTreeDataView | GetDataView
(
const FStateTreeExecutionFrame* ParentFrame, |
||
| FStateTreeDataView | GetDataView
(
FStateTreeInstanceStorage& InstanceDataStorage, |
||
| FStateTreeDataView | GetDataViewOrTemporary
(
const FStateTreeExecutionFrame* ParentFrame, |
||
| const FStateTreeEventQueue & | |||
| TConstArrayView< FStateTreeEvent > | |||
| FStateTreeExecutionState & | GetExecState () |
||
| const FStateTreeExecutionState & | GetExecState () |
||
| T::DataType & | GetExternalData
(
const T Handle |
Returns reference to external data based on provided handle. | |
| TConstArrayView< FStateTreeExternalDataDesc > | |||
| FStateTreeExternalDataHandle | GetExternalDataHandleByStruct
(
const UStruct* InStruct |
||
| T::DataType * | GetExternalDataPtr
(
const T Handle |
Returns pointer to external data based on provided item handle. | |
| FStateTreeDataView | GetExternalDataView
(
const FStateTreeExternalDataHandle Handle |
||
| const FStateTreeInstanceData * | |||
| T & | GetInstanceData
(
const FStateTreeNodeBase& Node |
||
| T::FInstanceDataType & | GetInstanceData
(
const T& Node |
||
| T * | GetInstanceDataPtr
(
const FStateTreeNodeBase& Node |
||
| TStateTreeInstanceDataStructRef< typename T::FInstanceDataType > | GetInstanceDataStructRef
(
const T& Node |
||
| FString | |||
| EStateTreeRunStatus | |||
| FStateTreeEventQueue & | |||
| FStateTreeInstanceData * | @retuen mutable references to the instance data in use, or nullptr if the context is not valid. | ||
| UObject * | GetOwner () |
||
| FString | GetSafeStateName
(
const FStateTreeExecutionFrame& CurrentFrame, |
||
| int32 | |||
| const FCompactStateTreeState * | GetStateFromHandle
(
const FStateTreeStateHandle StateHandle |
||
| FString | GetStateStatusString
(
const FStateTreeExecutionState& ExecState |
||
| const UStateTree * | GetStateTree () |
||
| EStateTreeRunStatus | |||
| UWorld * | GetWorld () |
||
| bool | HasEventToProcess
(
const FGameplayTag Tag |
||
| bool | IsHandleSourceValid
(
const FStateTreeExecutionFrame* ParentFrame, |
||
| bool | IsValid () |
||
| bool | RequestTransition
(
const FStateTreeExecutionFrame& CurrentFrame, |
Requests transition to a specified state with specified priority. | |
| void | RequestTransition
(
const FStateTreeTransitionRequest& Request |
Requests transition to a state. | |
| bool | SelectState
(
const FStateTreeExecutionFrame& CurrentFrame, |
Runs state selection logic starting at the specified state, walking towards the leaf states. | |
| bool | SelectStateInternal
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Used internally to do the recursive part of the SelectState(). | |
| void | SendEvent
(
const FStateTreeEvent& Event |
Sends event for the StateTree. | |
| void | SendEvent
(
const FGameplayTag Tag, |
Sends event for the StateTree. | |
| void | SetCollectExternalDataCallback
(
const FOnCollectStateTreeExternalData& Callback |
Sets callback used to collect external data views during State Tree execution. | |
| void | SetContextData
(
const FStateTreeExternalDataHandle Handle, |
Sets context data view value for specific item. | |
| bool | SetContextDataByName
(
const FName Name, |
Sets the context data based on name (name is defined in the schema), returns true if data was found | |
| void | Updates data view of the parameters by using the default values defined in the StateTree asset. | ||
| void | SetExternalData
(
const FStateTreeExternalDataHandle Handle, |
Sets external data view value for specific item. | |
| bool | SetGlobalParameters
(
const FInstancedPropertyBag& Parameters |
Stores copy of provided parameters as State Tree global parameters. | |
| void | SetParameters
(
const FInstancedPropertyBag& Parameters |
Updates data view of the parameters by replacing the default values defined in the StateTree asset by the provided values. | |
| void | SetupNextTransition
(
const FStateTreeExecutionFrame& CurrentFrame, |
Sets up NextTransition based on the provided parameters and the current execution status. | |
| EStateTreeRunStatus | Start
(
const FInstancedPropertyBag* InitialParameters |
Start executing. | |
| EStateTreeRunStatus | StartEvaluatorsAndGlobalTasks
(
FStateTreeIndex16& OutLastInitializedTaskIndex |
Starts evaluators and global tasks. | |
| EStateTreeRunStatus | StartTemporaryEvaluatorsAndGlobalTasks
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Starts temporary instances of global evaluators and tasks for a given frame. | |
| void | Handles logic for signalling State completed. | ||
| EStateTreeRunStatus | Stop
(
const EStateTreeRunStatus CompletionStatus |
Stop executing if the tree is running. | |
| void | StopEvaluatorsAndGlobalTasks
(
const EStateTreeRunStatus CompletionStatus, |
Stops evaluators and global tasks. | |
| void | StopTemporaryEvaluatorsAndGlobalTasks
(
TArrayView< FStateTreeTemporaryInstanceData > TempInstances |
Stops leftover global evaluators and tasks in the provided temporary instance data. | |
| bool | TestAllConditions
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Checks all conditions at given range | |
| EStateTreeRunStatus | Tick
(
const float DeltaTime |
Tick the state tree logic. | |
| EStateTreeRunStatus | TickEvaluatorsAndGlobalTasks
(
const float DeltaTime, |
Tick evaluators and global tasks by delta time. | |
| EStateTreeRunStatus | TickTasks
(
const float DeltaTime |
Ticks tasks of all active states starting from current state by delta time. | |
| bool | Triggers transitions based on current run status. | ||
| void | UpdateInstanceData
(
TConstArrayView< FStateTreeExecutionFrame > CurrentActiveFrames, |
Classes
| Type | Name | Description | |
|---|---|---|---|
| FAllowDirectTransitionsScope | Helper struct to track when it is allowed to request transitions. | ||
| FCollectedExternalDataCache | |||
| FCurrentlyProcessedFrameScope | Helper struct to track currently processed frame. | ||
| FCurrentlyProcessedStateScope | Helper struct to track currently processed state. | ||
| FNodeInstanceDataScope | Helper struct to set current node data. |
Constants
| Name | Description |
|---|---|
| MaxExecutionFrames | Max number of execution frames handled during state selection. |