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

#include <BTTask_GetNewLocationAround.h>

Inheritance diagram for UBTTask_GetNewLocationAround:

Public Member Functions

 UBTTask_GetNewLocationAround ()
 

Public Attributes

float Radius = 250.0f
 
FBlackboardKeySelector TargetObject
 
FBlackboardKeySelector MoveTargetLocation
 

Protected Member Functions

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

Constructor & Destructor Documentation

◆ UBTTask_GetNewLocationAround()

UBTTask_GetNewLocationAround::UBTTask_GetNewLocationAround ( )
15{
16 NodeName = TEXT("Get New Location Around Object/Point");
17}

Member Function Documentation

◆ ExecuteTask()

EBTNodeResult::Type UBTTask_GetNewLocationAround::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
20{
21 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_GetNewLocationAround::ExecuteTask);
22 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
23 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
24 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
25 if(BlackboardComp != nullptr)
26 {
27 FVector Location = FVector::ZeroVector;
28 const AActor* TargetActor = Cast<AActor>(BlackboardComp->GetValueAsObject(TargetObject.SelectedKeyName));
29 if(TargetActor == nullptr)
30 {
31 Location = BlackboardComp->GetValueAsVector(TargetObject.SelectedKeyName);
32 }
33 if(TargetActor != nullptr)
34 {
35 Location = TargetActor->GetActorLocation();
36 }
37 if(OwnerComp.GetAIOwner() != nullptr && !Location.IsZero())
38 {
39 const UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem(OwnerComp.GetAIOwner());
40 if(NavSystem != nullptr)
41 {
42 FNavLocation RandomPoint(Location);
43 const bool bFoundPoint = NavSystem->GetRandomReachablePointInRadius(Location, Radius, RandomPoint);
44 if(bFoundPoint)
45 {
46 BlackboardComp->SetValueAsVector(MoveTargetLocation.SelectedKeyName, RandomPoint);
47 return EBTNodeResult::Succeeded;
48 }
49 }
50 }
51 }
52 UBaseHelpersBPLib::PrintToLog(OwnerComp.GetAIOwner(), "BTTask_GetNewLocation Failed");
53 return EBTNodeResult::Failed;
54}
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_GetNewLocationAround.cpp:19
FBlackboardKeySelector MoveTargetLocation
Definition BTTask_GetNewLocationAround.h:26
FBlackboardKeySelector TargetObject
Definition BTTask_GetNewLocationAround.h:24
float Radius
Definition BTTask_GetNewLocationAround.h:21
static void PrintToLog(const UObject *WorldContextObject, const FString &Message, const bool bWarning=false, const bool bError=false)
Definition BaseHelpersBPLib.cpp:98

◆ GetStaticDescription()

FString UBTTask_GetNewLocationAround::GetStaticDescription ( ) const
overrideprotectedvirtual
57{
58 FString Description;
59 Description += FString::Printf(TEXT("\nRadius: %i"), FMath::RoundToInt(Radius));
60 if(TargetObject.SelectedKeyName.IsValid())
61 {
62 Description += FString::Printf(TEXT("\nTarget Object: %s"), *TargetObject.SelectedKeyName.ToString());
63 }
64 else
65 {
66 Description += TEXT("\nTarget Object: None");
67 }
68 if(MoveTargetLocation.SelectedKeyName.IsValid())
69 {
70 Description += FString::Printf(TEXT("\n Move Target Location Set"));
71 }
72 else
73 {
74 Description += TEXT("\nMove Target Location NULL");
75 }
76 return Description;
77}

Member Data Documentation

◆ MoveTargetLocation

FBlackboardKeySelector UBTTask_GetNewLocationAround::MoveTargetLocation

◆ Radius

float UBTTask_GetNewLocationAround::Radius = 250.0f

◆ TargetObject

FBlackboardKeySelector UBTTask_GetNewLocationAround::TargetObject

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