UBTService
#include "BehaviorTree/BTService.h" Description
The base class for Behavior Tree service nodes. Services run periodically in the background while their branch is active, typically updating blackboard values or performing lightweight checks.
Caveats & Gotchas
- • Override TickNode() for periodic updates. The interval is controlled by Interval and RandomDeviation properties on the node.
- • Services do not return results and cannot affect execution flow directly — use the Blackboard to communicate state to decorators and tasks.
- • OnBecomeRelevant() and OnCeaseRelevant() are called when the service's branch becomes active or inactive — use these to start/stop ongoing work.
Example
Periodically update a target distance on the blackboard C++
void UBTService_UpdateTargetDist::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
AAIController* Controller = OwnerComp.GetAIOwner();
AActor* Target = Cast<AActor>(OwnerComp.GetBlackboardComponent()->GetValueAsObject(FName("TargetActor")));
if (Controller && Target)
{
float Dist = FVector::Dist(Controller->GetPawn()->GetActorLocation(), Target->GetActorLocation());
OwnerComp.GetBlackboardComponent()->SetValueAsFloat(FName("TargetDistance"), Dist);
}
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?