UBehaviorTreeComponent::ForEachChildTask
#include "BehaviorTree/BehaviorTreeComponent.h"
Access: public
Description
Invokes the given functor once for every task node in every running instance on the stack. An overload also exists that scopes the walk to the children of a specific start node and instance index, found via FindInstanceContainingNode.
Caveats & Gotchas
- • The functor receives a reference, not a copy — do not store the UBTTaskNode& or FBehaviorTreeInstance& beyond the callback's scope, since the instance stack can reallocate on later ticks.
- • Walking the whole tree is O(number of nodes); prefer the scoped overload (with a start node and instance index) when you only need to inspect one branch.
Signature
void ForEachChildTask(TFunctionRef<void (UBTTaskNode&, const FBehaviorTreeInstance&, int32 InstanceIndex)> Functor) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Functor | TFunctionRef<void (UBTTaskNode&, const FBehaviorTreeInstance&, int32 InstanceIndex)> | Callback invoked once per task node found while walking the entire instance stack. | — |
Return Type
void Example
Counting all active task nodes across the tree C++
int32 TaskCount = 0;
OwnerComp.ForEachChildTask([&TaskCount](UBTTaskNode& Task, const FBehaviorTreeInstance& Instance, int32 InstanceIndex)
{
++TaskCount;
}); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?