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

#include <BTService_SetFocus.h>

Inheritance diagram for UBTService_SetFocus:

Public Member Functions

 UBTService_SetFocus ()
 

Public Attributes

bool bDoOnce = false
 
bool bFocusPoint = true
 
FBlackboardKeySelector Target
 
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 void TickNode (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, const float DeltaSeconds) override
 
virtual void OnBecomeRelevant (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
 
virtual FString GetStaticDescription () const override
 

Private Member Functions

bool SetFocusToActor (AActor *TargetActor, class AAIController *Controller) const
 

Constructor & Destructor Documentation

◆ UBTService_SetFocus()

UBTService_SetFocus::UBTService_SetFocus ( )
15{
16 NodeName = TEXT("Set Focus");
17 INIT_SERVICE_NODE_NOTIFY_FLAGS();
18#if WITH_EDITOR
19 bDebuggingMode = true;
20#endif // WITH_EDITOR
21}
bool bDebuggingMode
Definition BTService_SetFocus.h:31

Member Function Documentation

◆ GetStaticDescription()

FString UBTService_SetFocus::GetStaticDescription ( ) const
overrideprotectedvirtual
141{
142 FString Description;
144 {
145 Description += FString::Printf(TEXT("\n DEBUG ACTIVE"));
146 }
147 if(Target.SelectedKeyName.IsValid())
148 {
149 Description += FString::Printf(TEXT("\nTarget : %s"), *Target.SelectedKeyName.ToString());
150 }
151 else
152 {
153 Description += TEXT("\nTarget : None");
154 }
155 return Description;
156}
FBlackboardKeySelector Target
Definition BTService_SetFocus.h:27

◆ OnBecomeRelevant()

void UBTService_SetFocus::OnBecomeRelevant ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
80{
81 TRACE_CPUPROFILER_EVENT_SCOPE(UBTService_SetFocus::OnBecomeRelevant);
82 Super::OnBecomeRelevant(OwnerComp, NodeMemory);
83 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
84 if(BlackboardComp == nullptr){return;}
85 AAIController* AIController = OwnerComp.GetAIOwner();
86 if(AIController == nullptr){return;}
87 UObject* TargetObject = BlackboardComp->GetValueAsObject(Target.SelectedKeyName);
88 if(TargetObject != nullptr)
89 {
90 AActor* TargetActor = Cast<AActor>(TargetObject);
91 if(TargetActor == nullptr){return;}
92 SetFocusToActor(TargetActor, AIController);
93 }
94 else
95 {
96 AIController->SetFocalPoint(BlackboardComp->GetValueAsVector(Target.SelectedKeyName));
97 }
98}
bool SetFocusToActor(AActor *TargetActor, class AAIController *Controller) const
Definition BTService_SetFocus.cpp:100
virtual void OnBecomeRelevant(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTService_SetFocus.cpp:79

◆ SetFocusToActor()

bool UBTService_SetFocus::SetFocusToActor ( AActor * TargetActor,
class AAIController * Controller ) const
private
101{
102 TRACE_CPUPROFILER_EVENT_SCOPE(UBTService_SetFocus::SetFocusToActor);
103 if(TargetActor == nullptr){return false;}
104 if(Controller == nullptr){return false;}
105 if(bFocusPoint)
106 {
107 FVector FocalPoint;
108 const IInteractionInterface* InteractionActor = Cast<IInteractionInterface>(TargetActor);
109 if(InteractionActor != nullptr)
110 {
111 FocalPoint = InteractionActor->GetInteractionLocation();
112 }
113 else
114 {
115 FocalPoint = TargetActor->GetActorLocation();
116 }
117 Controller->SetFocalPoint(FocalPoint);
119 {
120 const FVector StartLocation = Controller->GetPawn()->GetPawnViewLocation();
121 DrawDebugLine(GetWorld(), StartLocation, FocalPoint, TargetLineColor, false, LineLifetime, 0, LineThickness);
122 DrawDebugPoint(GetWorld(), FocalPoint, PointSize, TargetPointColor,false, LineLifetime, 0);
123 }
124 }
125 else
126 {
127 Controller->SetFocus(TargetActor);
129 {
130 const FVector StartLocation = Controller->GetPawn()->GetPawnViewLocation();
131 const FVector EndLocation = TargetActor->GetActorLocation();
132 DrawDebugLine(GetWorld(), StartLocation, EndLocation, TargetLineColor, false, LineLifetime, 0, LineThickness);
133 DrawDebugPoint(GetWorld(), EndLocation, PointSize, TargetPointColor,false, LineLifetime, 0);
134 }
135 }
136 return true;
137}
Definition InteractionInterface.h:18
virtual FVector GetInteractionLocation() const =0
float LineThickness
Definition BTService_SetFocus.h:37
float LineLifetime
Definition BTService_SetFocus.h:35
FColor TargetLineColor
Definition BTService_SetFocus.h:41
bool bFocusPoint
Definition BTService_SetFocus.h:25
FColor TargetPointColor
Definition BTService_SetFocus.h:39
float PointSize
Definition BTService_SetFocus.h:33

◆ TickNode()

void UBTService_SetFocus::TickNode ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory,
const float DeltaSeconds )
overrideprotectedvirtual
24{
25 TRACE_CPUPROFILER_EVENT_SCOPE(UBTService_SetFocus::TickNode);
26 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
27 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Services);
28 Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
29 if(bDoOnce){return;}
30 // FBTTaskFocusMemory* FocusMemory = reinterpret_cast<FBTTaskFocusMemory*>(NodeMemory);
31 // if(FocusMemory == nullptr){return;}
32 // FocusMemory->FocalPoint = FVector::ZeroVector;
33 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
34 if(BlackboardComp == nullptr){return;}
35 AAIController* AIController = OwnerComp.GetAIOwner();
36 if(AIController == nullptr){return;}
37 UObject* TargetObject = BlackboardComp->GetValueAsObject(Target.SelectedKeyName);
38 if(TargetObject != nullptr)
39 {
40 AActor* TargetActor = Cast<AActor>(TargetObject);
41 if(TargetActor == nullptr){return;}
42 SetFocusToActor(TargetActor, AIController);
43 // const IInteractionInterface* InteractionActor = Cast<IInteractionInterface>(TargetActor);
44 // if(InteractionActor)
45 // {
46 // FocusMemory->FocalPoint = InteractionActor->GetInteractionLocation();
47 // }
48 // else
49 // {
50 // FocusMemory->FocalPoint = TargetActor->GetActorLocation();
51 // }
52 }
53 else
54 {
55 AIController->SetFocalPoint(BlackboardComp->GetValueAsVector(Target.SelectedKeyName));
57 {
58 const FVector StartLocation = AIController->GetPawn()->GetPawnViewLocation();
59 const FVector EndLocation = BlackboardComp->GetValueAsVector(Target.SelectedKeyName);
60 DrawDebugLine(GetWorld(), StartLocation, EndLocation, TargetLineColor, false, LineLifetime, 0, LineThickness);
61 DrawDebugPoint(GetWorld(), EndLocation, PointSize, TargetPointColor,false, LineLifetime, 0);
62 }
63 }
64 //
65 // if (AAIController* AIController = OwnerComp.GetAIOwner())
66 // {
67 // if(bFocusPoint)
68 // {
69 // AIController->SetFocalPoint(FocusMemory->FocalPoint);
70 // }
71 // else
72 // {
73 // AIController->SetFocus();
74 // }
75 // }
76 //
77}
virtual void TickNode(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, const float DeltaSeconds) override
Definition BTService_SetFocus.cpp:23
bool bDoOnce
Definition BTService_SetFocus.h:23

Member Data Documentation

◆ bDebuggingMode

bool UBTService_SetFocus::bDebuggingMode = false

◆ bDoOnce

bool UBTService_SetFocus::bDoOnce = false

◆ bFocusPoint

bool UBTService_SetFocus::bFocusPoint = true

◆ LineLifetime

float UBTService_SetFocus::LineLifetime = 20.0f

◆ LineThickness

float UBTService_SetFocus::LineThickness = 1.0f

◆ PointSize

float UBTService_SetFocus::PointSize = 20.0f

◆ Target

FBlackboardKeySelector UBTService_SetFocus::Target

◆ TargetLineColor

FColor UBTService_SetFocus::TargetLineColor = FColor::Red

◆ TargetPointColor

FColor UBTService_SetFocus::TargetPointColor = FColor::Red

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