Get owner actor in UBTTaskNode::ExecuteTask

Hello, I’m trying to write BehaviourTree task node in C++ and I have 2 questions:

How do I get Owner Actor - the AI controller (in blueprints it’s avilable as a connector from Event Receive Execute)?

Should I return Super::ExecuteTask(OwnerComp, NodeMemory) at the end of function?

1 Like

OwnerComp.GetAIOwner(); // to get the controller
AIOwner->GetPawn(); // to get the actor

You should return the result your node decides and do not need to call Super.

1 Like

Is the return value stored in some variable?

Yes, to add to luthage’s answer:

AAIController* AIOwner = OwnerComp.GetAIOwner(); // to get the controller
APawn* Pawn = AIOwner->GetPawn(); // to get the actor

You’ll need to add this include:

#include "AIController.h"

What do you mean is it stored is some variable? You execute your task and then return whether the task succeeded or not.

Perhaps you should look at the code of the tasks that Epic provided. Shooter game is another good example.