#unreal

Custom tasks, evaluators and conditions can be written both in C++ and BP’s. C++ offers better control, such as not making tasks tick.

GetExternalData

Usage

This function can be used to load objects from outside the state tree. This works by defining a handle, and linking it:

//In your header
TStateTreeExternalDataHandle<AAIController> ControllerHandle;
 
virtual bool Link(FStateTreeLinker& Linker) override;
 
//.cpp file
bool FMySTT::Link(FStateTreeLinker& Linker)
{
	Linker.LinkExternalData(ControllerHandle);
	return true;
}
 
EStateTreeRunStatus FMySTT::EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const
{
	AAIController& Controller = Context.GetExternalData(ControllerHandle);
	// ....
}

How it works

The data available via GetExternalData is defined in UStateTreeComponent (if you use Mass state trees there’s probably different place which I’ve not looked at)

UStateTreeComponent has a function SetContextRequirements which is used to fill external data into the tree. Check its implementation for specifics.

State tree performance

Measure with Unreal Insights. State Tree total seems to show up as “StateTree”. Blueprint based tasks seem to perform significantly worse than C++ based tasks, so depending on how often the tasks execute, using C++ may give decent performance benefits.

Other issues

Issues valid at least for Unreal Engine 5.3

  • State Trees cannot be changed at runtime if ran through the StateTreeComponent
  • State Trees might be possible to run outside of the component, but no builtin support for it