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. | |
| bool | bRecordTransitions | If true, the state tree context will create snapshots of transition events and capture them within RecordedTransitions for later use. | |
| 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. | |
| FStateTreeFrameStateSelectionEvents * | CurrentlyProcessedStateSelectionEvents | Current frames events we're processing during the state selection, or invalid if not applicable. | |
| const FStateTreeEvent * | CurrentlyProcessedTransitionEvent | Current event we're processing in transition, or invalid if not applicable. | |
| FStateTreeDataHandle | CurrentNodeDataHandle | Currently processed nodes instance data. | |
| FStateTreeDataView | CurrentNodeInstanceData | ||
| TSharedPtr< FStateTreeEventQueue > | EventQueue | Events queue to use, cached for less indirections. | |
| FStateTreeInstanceData & | InstanceData | Instance data used during current tick. | |
| FStateTreeInstanceStorage * | InstanceDataStorage | Data storage of the instance data, cached for less indirections. | |
| const FStateTreeReferenceOverrides * | LinkedStateTreeOverrides | Pointer to linked state tree overrides. | |
| 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. | |
| TArray< FRecordedStateTreeTransitionResult > | RecordedTransitions | Captured snapshots for transition results that can be used to recreate transitions. | |
| const UStateTree & | RootStateTree | The StateTree asset the context is initialized for |
Constructors
| Type | Name | Description | |
|---|---|---|---|
FStateTreeExecutionContext
(
const FStateTreeExecutionContext& InContextToCopy, |
Construct an execution context from a parent context and another tree. | ||
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. | |
| void | CallStopOnEvaluatorsAndGlobalTasks
(
const FStateTreeExecutionFrame* ParentFrame, |
Stops evaluators and global tasks of the given frame. Expects nodes data to be already bound. | |
| void | CaptureNewStateEvents
(
TConstArrayView< FStateTreeExecutionFrame > PrevFrames, |
Captures StateTree events used during the state selection. | |
| bool | Collects external data for all StateTrees in active frames. | ||
| FStateTreeIndex16 | CollectExternalData
(
const UStateTree* StateTree |
Collects external data for specific State Tree asset. | |
| void | ConsumeEvent
(
const FStateTreeSharedEvent& Event |
Consumes and removes the specified event from the event queue. | |
| 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 | EvaluatePropertyFunctionsOnActiveInstances
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Evaluate all function at given range. | |
| void | EvaluatePropertyFunctionsWithValidation
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Evaluate all function at given range. | |
| float | EvaluateUtility
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Calculate the final score of all considerations at given range | |
| void | ExitState
(
const FStateTreeTransitionResult& Transition |
Handles logic for exiting State. | |
| const FStateTreeExecutionFrame * | FindFrame
(
const UStateTree* StateTree, |
Looks for a frame in provided list of frames. | |
| EStateTreeRunStatus | ForceTransition
(
const FRecordedStateTreeTransitionResult& Transition |
Forces transition to a state from a previously recorded state tree transition result. | |
| TEnableIf< TIsInvocable< TFunc, FStateTreeEvent >::Value, void >::Type | ForEachEvent
(
TFunc&& Function |
Iterates over all events. | |
| TEnableIf< TIsInvocable< TFunc, FStateTreeSharedEvent >::Value, void >::Type | 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 | GetDataViewFromInstanceStorage
(
FStateTreeInstanceStorage& InstanceDataStorage, |
||
| FStateTreeDataView | GetDataViewOrTemporary
(
const FStateTreeExecutionFrame* ParentFrame, |
||
| const FStateTreeEventQueue & | |||
| TConstArrayView< FStateTreeEvent > | |||
| TConstArrayView< FStateTreeSharedEvent > | |||
| 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::FInstanceDataType & | GetInstanceData
(
const T& Node |
||
| T & | GetInstanceData
(
const FStateTreeNodeBase& Node |
||
| T * | GetInstanceDataPtr
(
const FStateTreeNodeBase& Node |
||
| TStateTreeInstanceDataStructRef< typename T::FInstanceDataType > | GetInstanceDataStructRef
(
const T& Node |
||
| FString | |||
| EStateTreeRunStatus | |||
| const FStateTreeReference * | GetLinkedStateTreeOverrideForTag
(
const FGameplayTag StateTag |
||
| FStateTreeEventQueue & | |||
| TArrayView< FStateTreeSharedEvent > | |||
| FStateTreeInstanceData * | |||
| UObject * | GetOwner () |
||
| TConstArrayView< FRecordedStateTreeTransitionResult > | Returns the recorded transitions for this context. | ||
| 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 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 | SetLinkedStateTreeOverrides
(
const FStateTreeReferenceOverrides* InLinkedStateTreeOverrides |
||
| 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 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
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Stops temporary global evaluators and tasks for the provided frame. | |
| bool | TestAllConditions
(
const FStateTreeExecutionFrame* CurrentParentFrame, |
Checks all conditions at given range | |
| EStateTreeRunStatus | Tick
(
const float DeltaTime |
Tick the state tree logic, updates the tasks and triggers transitions. | |
| EStateTreeRunStatus | TickEvaluatorsAndGlobalTasks
(
const float DeltaTime, |
Tick evaluators and global tasks by delta time. | |
| EStateTreeRunStatus | TickPostlude () |
||
| EStateTreeRunStatus | TickPrelude () |
Common functionality shared by the tick methods. | |
| EStateTreeRunStatus | TickTasks
(
const float DeltaTime |
Ticks tasks of all active states starting from current state by delta time. | |
| EStateTreeRunStatus | Tick the state tree logic partially, triggers the transitions. | ||
| void | Handles transition triggering part of the tick. | ||
| EStateTreeRunStatus | TickUpdateTasks
(
const float DeltaTime |
Tick the state tree logic partially, updates the tasks. | |
| void | TickUpdateTasksInternal
(
const float DeltaTime |
Handles task ticking part of the tick. | |
| 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 | |||
| FCurrentFrameStateSelectionEventsScope | Helper struct to track currently processed state selection events. | ||
| FCurrentlyProcessedFrameScope | Helper struct to track currently processed frame. | ||
| FCurrentlyProcessedStateScope | Helper struct to track currently processed state. | ||
| FCurrentlyProcessedTransitionEventScope | Helper struct to track currently processed transition event. | ||
| FNodeInstanceDataScope | Helper struct to set current node data. | ||
| FStateSelectionResult | Describes a result of States Selection. |