See also: StateTree InstanceData

Basic C++ structure

struct EXAMPLE_API FSTT_DoTask : public FStateTreeTaskCommonBase
	using FInstanceDataType = FMyInstanceData;
	virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
	virtual const UStruct* GetInstanceDataType() const override { return FInstanceDataType::StaticStruct(); }

Run status

Tasks can return different run status values when entered and when ticking. Returning Running means the task continues running, while other statuses will cause the task to end.

In Blueprint-based tasks, the task will be in Running state until you call Finish Task.

Task design

Important: If your task returns any other status besides running this will cause the task to complete. This means the current state will trigger any complete/success/failure transitions - this will happen even if you have multiple tasks within a state. Only one needs to complete to trigger the transitions.

There are two common types of tasks you will have:

  • Tasks which retrieve some data from somewhere so you can use it elsewhere in the state tree
  • Tasks which perform some kind of actions

As a result of the behavior above, tasks which retrieve data should usually return Running even if technically they have finished retrieving data. This allows your other tasks/states which use this data to actually do something without exiting too early.

Similarly, tasks which perform actions should usually return a status value reflecting their actual result - success, failure or running if the task is not yet finished.

For blueprint based tasks, this means you should not call Finish Task unless you intend for the task to potentially trigger state transitions.

See also StateTree InstanceData


If you use a task which completes as a Global Task, the entire state tree will stop immediately. This doesn’t produce any logs or any other information to warn you about it.