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

#include <BTTask_SetFocus.h>

Inheritance diagram for UBTTask_SetFocus:

Public Member Functions

 UBTTask_SetFocus ()
 

Public Attributes

bool bFocusPoint = false
 
FBlackboardKeySelector TargetFocus
 
bool bDebuggingMode = false
 
float PointSize = 20.0f
 
float LineLifetime = 20.0f
 
float LineThickness = 1.0f
 
FColor TargetPointColor = FColor::Red
 
FColor TargetLineColor = FColor::Red
 

Protected Member Functions

virtual EBTNodeResult::Type ExecuteTask (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
 
virtual FString GetStaticDescription () const override
 

Detailed Description

The UBTTask_SetFocus class is a task node used in behavior trees to set the focus of an AI controller.

Inherits from: UBTTaskNode

Constructor & Destructor Documentation

◆ UBTTask_SetFocus()

UBTTask_SetFocus::UBTTask_SetFocus ( )
14{
15 NodeName = TEXT("Set Focus");
16}

Member Function Documentation

◆ ExecuteTask()

EBTNodeResult::Type UBTTask_SetFocus::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
19{
20 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_SetFocus::ExecuteTask);
21 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
22 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
23 if(OwnerComp.GetAIOwner() == nullptr){return EBTNodeResult::Failed;}
24 AAIController* AIController = OwnerComp.GetAIOwner();
25 if(AIController == nullptr){return EBTNodeResult::Failed;}
26 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
27 if(BlackboardComp == nullptr){return EBTNodeResult::Failed;}
28 FVector FocalPoint = FVector::ZeroVector;
29
30 UObject* TargetObject = BlackboardComp->GetValueAsObject(TargetFocus.SelectedKeyName);
31 if(TargetObject != nullptr)
32 {
33 AActor* TargetActor = Cast<AActor>(TargetObject);
34 if(TargetActor != nullptr)
35 {
36 const IInteractionInterface* InteractionActor = Cast<IInteractionInterface>(TargetActor);
37 if(InteractionActor != nullptr)
38 {
39 FocalPoint = InteractionActor->GetInteractionLocation();
40 }
41 else
42 {
43 FocalPoint = TargetActor->GetActorLocation();
44 }
45 if(bFocusPoint)
46 {
47 AIController->SetFocalPoint(FocalPoint);
48 }
49 else
50 {
51 AIController->SetFocus(TargetActor);
52 }
54 {
55 const FVector StartLocation = AIController->GetPawn()->GetPawnViewLocation();
56 const FVector EndLocation = TargetActor->GetActorLocation();
57 DrawDebugLine(GetWorld(), StartLocation, EndLocation, TargetLineColor, false, LineLifetime, 0, LineThickness);
58 DrawDebugPoint(GetWorld(), EndLocation, PointSize, TargetPointColor,false, LineLifetime, 0);
59 }
60 }
61 }
62 else
63 {
64 FocalPoint = BlackboardComp->GetValueAsVector(TargetFocus.SelectedKeyName);
65 AIController->SetFocalPoint(FocalPoint);
67 {
68 const FVector StartLocation = AIController->GetPawn()->GetPawnViewLocation();
69 const FVector EndLocation = BlackboardComp->GetValueAsVector(TargetFocus.SelectedKeyName);
70 DrawDebugLine(GetWorld(), StartLocation, EndLocation, TargetLineColor, false, LineLifetime, 0, LineThickness);
71 DrawDebugPoint(GetWorld(), EndLocation, PointSize, TargetPointColor,false, LineLifetime, 0);
72 }
73 }
74
75 return EBTNodeResult::Succeeded;
76}
Definition InteractionInterface.h:18
virtual FVector GetInteractionLocation() const =0
bool bFocusPoint
Definition BTTask_SetFocus.h:26
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_SetFocus.cpp:18
bool bDebuggingMode
Definition BTTask_SetFocus.h:31
float LineLifetime
Definition BTTask_SetFocus.h:35
FColor TargetPointColor
Definition BTTask_SetFocus.h:39
FBlackboardKeySelector TargetFocus
Definition BTTask_SetFocus.h:28
FColor TargetLineColor
Definition BTTask_SetFocus.h:41
float PointSize
Definition BTTask_SetFocus.h:33
float LineThickness
Definition BTTask_SetFocus.h:37

◆ GetStaticDescription()

FString UBTTask_SetFocus::GetStaticDescription ( ) const
overrideprotectedvirtual
79{
80 FString Description;
81 if(TargetFocus.SelectedKeyName.IsValid())
82 {
83 Description += FString::Printf(TEXT("\nTarget Actor: %s"), *TargetFocus.SelectedKeyName.ToString());
84 }
85 else
86 {
87 Description += TEXT("\nTarget Actor: None");
88 }
89 return Description;
90}

Member Data Documentation

◆ bDebuggingMode

bool UBTTask_SetFocus::bDebuggingMode = false

◆ bFocusPoint

bool UBTTask_SetFocus::bFocusPoint = false

◆ LineLifetime

float UBTTask_SetFocus::LineLifetime = 20.0f

◆ LineThickness

float UBTTask_SetFocus::LineThickness = 1.0f

◆ PointSize

float UBTTask_SetFocus::PointSize = 20.0f

◆ TargetFocus

FBlackboardKeySelector UBTTask_SetFocus::TargetFocus

◆ TargetLineColor

FColor UBTTask_SetFocus::TargetLineColor = FColor::Red

◆ TargetPointColor

FColor UBTTask_SetFocus::TargetPointColor = FColor::Red

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