Space Plunder
Loading...
Searching...
No Matches
UBTTask_InteractWithTarget Class Reference

#include <BTTask_InteractWithTarget.h>

Inheritance diagram for UBTTask_InteractWithTarget:

Classes

struct  FBTTaskInteractWithTargetMemory
 

Public Member Functions

 UBTTask_InteractWithTarget ()
 

Public Attributes

float DelayDuration = 0.2f
 
int32 Attempts = 4
 
FBlackboardKeySelector TargetObject
 
FBlackboardKeySelector bIsSomethingInTheWay
 
bool bDebuggingMode = false
 

Protected Member Functions

virtual EBTNodeResult::Type ExecuteTask (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
 
virtual EBTNodeResult::Type AbortTask (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
 
virtual void TickTask (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
 
virtual uint16 GetInstanceMemorySize () const override
 
virtual FString GetStaticDescription () const override
 

Detailed Description

UBTTask_InteractWithTarget is a behavior tree task node that is used to interact with a target object. It executes a series of attempts to interact with the target object, with a delay between attempts.

Constructor & Destructor Documentation

◆ UBTTask_InteractWithTarget()

UBTTask_InteractWithTarget::UBTTask_InteractWithTarget ( )
15{
16 NodeName = TEXT("Interact With Target");
17 INIT_TASK_NODE_NOTIFY_FLAGS();
18#if WITH_EDITOR
19 bDebuggingMode = true;
20#endif // WITH_EDITOR
21
22}
bool bDebuggingMode
Definition BTTask_InteractWithTarget.h:32

Member Function Documentation

◆ AbortTask()

EBTNodeResult::Type UBTTask_InteractWithTarget::AbortTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
69{
70 FBTTaskInteractWithTargetMemory* InteractMemory = reinterpret_cast<FBTTaskInteractWithTargetMemory*>(NodeMemory);
71 if(InteractMemory == nullptr){FinishLatentTask(OwnerComp, EBTNodeResult::Failed);}
72 InteractMemory->TotalAttempts = 0;
73 InteractMemory->StartTime = 0.0f;
74 InteractMemory->TargetActor = nullptr;
75 return EBTNodeResult::Aborted;
76}

◆ ExecuteTask()

EBTNodeResult::Type UBTTask_InteractWithTarget::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual

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.

Parameters
OwnerCompThe behavior tree component that is executing this task.
NodeMemoryPointer to the memory allocated for this node.
Returns
The execution result of the task, which can be "Succeeded" if the pickup operation was successful, "InProgress" if the pickup operation is currently in progress, or eventually "Failed" if the pickup operation fails.
40{
41 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_InteractWithTarget::ExecuteTask);
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;}
54 IAIActionsInterface* AIActions = Cast<IAIActionsInterface>(OwnerComp.GetAIOwner());
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

◆ GetInstanceMemorySize()

uint16 UBTTask_InteractWithTarget::GetInstanceMemorySize ( ) const
overrideprotectedvirtual
103{
104 return sizeof(FBTTaskInteractWithTargetMemory);
105}

◆ GetStaticDescription()

FString UBTTask_InteractWithTarget::GetStaticDescription ( ) const
overrideprotectedvirtual
108{
109 FString Description;// = Super::GetStaticDescription();
110 Description += FString::Printf(TEXT("\nAttempts: %s Delay between: %i"), *FString::FromInt(Attempts), FMath::RoundToInt(DelayDuration));
112 {
113 Description += FString::Printf(TEXT("\n DEBUG ACTIVE"));
114 }
115
116 if(TargetObject.SelectedKeyName.IsValid())
117 {
118 Description += FString::Printf(TEXT("\nTarget Object: %s"), *TargetObject.SelectedKeyName.ToString());
119 }
120 else
121 {
122 Description += TEXT("\nTarget Object: None");
123 }
124 if(bIsSomethingInTheWay.SelectedKeyName.IsValid())
125 {
126 Description += FString::Printf(TEXT("\n Something In The Way Set"));
127 }
128 else
129 {
130 Description += TEXT("\nSomething In The Way NULL");
131 }
132 return Description;
133}
float DelayDuration
Definition BTTask_InteractWithTarget.h:23
FBlackboardKeySelector bIsSomethingInTheWay
Definition BTTask_InteractWithTarget.h:29

◆ TickTask()

void UBTTask_InteractWithTarget::TickTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory,
float DeltaSeconds )
overrideprotectedvirtual
79{
80 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_InteractWithTarget::TickTask);
81 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
82 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
83 const FBTTaskInteractWithTargetMemory* InteractMemory = reinterpret_cast<FBTTaskInteractWithTargetMemory*>(NodeMemory);
84 if(InteractMemory == nullptr){FinishLatentTask(OwnerComp, EBTNodeResult::Failed);}
85 if(GetWorld()->GetTimeSeconds() - InteractMemory->StartTime >= DelayDuration)
86 {
87 ExecuteTask(OwnerComp, NodeMemory);
88 if(Attempts <= 0)
89 {
90 //- Couldn't pick up item //
91 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
92 if(BlackboardComp != nullptr)
93 {
94 BlackboardComp->SetValueAsBool(bIsSomethingInTheWay.SelectedKeyName, true);
95 BlackboardComp->SetValueAsObject(TargetObject.SelectedKeyName, InteractMemory->TargetActor);
96 }
97 FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
98 }
99 }
100}
virtual void TickTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
Definition BTTask_InteractWithTarget.cpp:78

Member Data Documentation

◆ Attempts

int32 UBTTask_InteractWithTarget::Attempts = 4

◆ bDebuggingMode

bool UBTTask_InteractWithTarget::bDebuggingMode = false

◆ bIsSomethingInTheWay

FBlackboardKeySelector UBTTask_InteractWithTarget::bIsSomethingInTheWay

◆ DelayDuration

float UBTTask_InteractWithTarget::DelayDuration = 0.2f

◆ TargetObject

FBlackboardKeySelector UBTTask_InteractWithTarget::TargetObject

The documentation for this class was generated from the following files: