Executes the task of interacting with the target actor.
This method is responsible for picking up an object (target actor) by calling the PickupObject() method of the AI owner. It gets the target actor from the blackboard component using the selected key name specified in the "TargetObject" variable. If the target actor is not found or if the pickup operation fails, it returns "Succeeded". Otherwise, it returns "InProgress". The start time of the task is also recorded in the "StartTime" member variable.
40{
42 FBTTaskInteractWithTargetMemory* InteractMemory = reinterpret_cast<FBTTaskInteractWithTargetMemory*>(NodeMemory);
43 if(InteractMemory == nullptr){return EBTNodeResult::Failed;}
44 InteractMemory->StartTime = GetWorld()->GetTimeSeconds();
45 if(InteractMemory->TotalAttempts == -1)
46 {
47 InteractMemory->TotalAttempts =
Attempts;
48 }
49 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
50 if(BlackboardComp != nullptr)
51 {
52 InteractMemory->TargetActor = Cast<AActor>(BlackboardComp->GetValueAsObject(
TargetObject.SelectedKeyName));
53 if(InteractMemory->TargetActor == nullptr){return EBTNodeResult::Succeeded;}
55 if(AIActions != nullptr)
56 {
57 const bool bSucceeded = AIActions->
PickupObject(InteractMemory->TargetActor);
58 if(bSucceeded)
59 {
60 return EBTNodeResult::Succeeded;
61 }
62 }
63 }
64 InteractMemory->TotalAttempts--;
65 return EBTNodeResult::InProgress;
66}
Definition AIActionsInterface.h:20
virtual bool PickupObject(const AActor *TargetObject)=0
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_InteractWithTarget.cpp:39
FBlackboardKeySelector TargetObject
Definition BTTask_InteractWithTarget.h:27
int32 Attempts
Definition BTTask_InteractWithTarget.h:25