Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to implement BTService in C++

Hi there! I am trying to convert my Behavior Tree tasks,services,etc. from BP into C++ for faster runtime and more customisation.

However I can't seem to figure out how to implement a Service in C++. As the events defined in BP like Event Receive Activation AI and Event Receive Tick(I use these currently,use Receive Activation to initialize some values) are not available in BTService.h but only in the blueprint version BTService_BlueprintBase.h My class derives from BTService. So i am not sure what functions correspond to those two functions in case of C++. It's especially confusing since the Service has already a Tick function just after creating the class.

Looked into the source code trying to figure out and found TickNode() and OnBecomeRelevant().However can't really decide if these are what i need to replicate the blueprint execution. Also if Tick function is already implemented how can i access it so i can implement what i want based on my BP? Do i even need TickNode() if the Service has already a Tick() function when i look at it in the BT?

Sorry if this is obvious but my c++ skills or rather my source code reading ability is apparently lacking.


Product Version: UE 4.13
more ▼

asked Jan 16 '17 at 03:45 PM in C++ Programming

avatar image

46 3 5 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

In .h file:

 virtual void OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;

In .cpp file (example):

 // Constructor:
 UBTService_MyService::UBTService_MyService(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
     NodeName = "My Service";
     bNotifyBecomeRelevant = true;    // necessarily!!!
     //bNotifyCeaseRelevant = true;
     // accept only actors and vectors
     BlackboardKey.AddVectorFilter(this, GET_MEMBER_NAME_CHECKED(UBTService_MyService, BlackboardKey));
     BlackboardKey.SelectedKeyName = FName("NameOfKey");
     BlackboardKey.SelectedKeyType = UBlackboardKeyType_Vector::StaticClass();
     Interval = 0.5f;    // Any value.
     RandomDeviation = 0.f;
 void UBTService_MyService::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
     Super::OnBecomeRelevant(OwnerComp, NodeMemory);
     UBlackboardComponent* CurretnBlackboard = OwnerComp.GetBlackboardComponent();
     if (OwnerComp.GetAIOwner() && OwnerComp.GetAIOwner()->GetPawn())
         AIPawn = OwnerComp.GetAIOwner()->GetPawn();

more ▼

answered Nov 17 '18 at 04:54 AM

avatar image

16 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users


Errmm i got into service,tasks ands stuff by analyzing the services given by UE4. For example UBTService_RunEQS shows how to tick, how to init and so on.

On BecomeRelevant/onCeaserelevant is mostly like what u want, since they get called whenever the service gets activated/deactivated(this means when the BHT is active on the node or a child). I use becomerelevane/Cease for example to set blackboardkey observers, so ican react on changeing ot a value.

Hope it helps

more ▼

answered Aug 20 '18 at 07:26 PM

avatar image

62 5 4 7

avatar image GS_Aero Nov 17 '18 at 04:57 AM


 bNotifyBecomeRelevant = true;

in constructor.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question