RealDocs

UBehaviorTreeComponent::SetDynamicSubtree

function AIModule Blueprint Since 4.0
#include "BehaviorTree/BehaviorTreeComponent.h"
Access: public Specifiers: UFUNCTIONBlueprintCallablevirtual

Description

Assigns a behavior tree asset to a RunBehaviorDynamic task in the running tree identified by InjectTag, allowing subtrees to be swapped in at runtime without restarting the whole tree.

Caveats & Gotchas

  • InjectTag must match a RunBehaviorDynamic task node's configured tag, or the call has no effect since no matching injection point is found.
  • There is an overload taking an additional UBTCompositeNode* starting node to skip searching the whole tree — prefer it when the injection point is already known for performance-sensitive code.
  • Assigning a new asset while the previous dynamic subtree is actively running will stop and replace it, which can interrupt in-progress tasks in that subtree.

Signature

virtual void SetDynamicSubtree(FGameplayTag InjectTag, UBehaviorTree* BehaviorAsset);

Parameters

Name Type Description Default
InjectTag FGameplayTag The tag identifying the RunBehaviorDynamic task slot to inject into.
BehaviorAsset UBehaviorTree* The behavior tree asset to assign as the dynamic subtree.

Return Type

void

Example

Swap in a subtree at runtime C++
BehaviorTreeComponent->SetDynamicSubtree(FGameplayTag::RequestGameplayTag(TEXT("AI.Subtree.CombatPhase2")), CombatPhase2Tree);

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.