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

#include <BTT_GetRandomLocation.h>

Inheritance diagram for UBTT_GetRandomLocation:

Public Member Functions

 UBTT_GetRandomLocation ()
 

Public Attributes

FBlackboardKeySelector MoveTargetLocation
 
float MaxDistance = 1000.0f
 
TSubclassOf< UNavigationQueryFilter > Filter = nullptr
 

Protected Member Functions

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

Constructor & Destructor Documentation

◆ UBTT_GetRandomLocation()

UBTT_GetRandomLocation::UBTT_GetRandomLocation ( )
15{
16 NodeName = TEXT("Get Random Location");
17 MoveTargetLocation.AddVectorFilter(this, GET_MEMBER_NAME_CHECKED(UBTT_GetRandomLocation, MoveTargetLocation));
18}
Definition BTT_GetRandomLocation.h:14
FBlackboardKeySelector MoveTargetLocation
Definition BTT_GetRandomLocation.h:22

Member Function Documentation

◆ ExecuteTask()

EBTNodeResult::Type UBTT_GetRandomLocation::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
21{
22 TRACE_CPUPROFILER_EVENT_SCOPE(UBTT_GetRandomLocation::ExecuteTask);
23 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
24 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
25 UWorld* World = GetWorld();
26 UNavigationSystemV1* NavigationSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(World);
27 const APawn* Pawn = OwnerComp.GetAIOwner()->GetPawn();
28 if(NavigationSystem != nullptr && Pawn != nullptr)
29 {
30 FSharedConstNavQueryFilter SharedFilter = nullptr;
31 if(Filter != nullptr)
32 {
33 const ANavigationData* NavData = NavigationSystem->GetDefaultNavDataInstance(FNavigationSystem::DontCreate);
34 if(NavData != nullptr)
35 {
36 SharedFilter = UNavigationQueryFilter::GetQueryFilter(*NavData, World, Filter);
37 }
38 }
39 const FVector Origin = Pawn->GetActorLocation();
40 FNavLocation Destination;
41
42 if(NavigationSystem->GetRandomReachablePointInRadius(Origin, MaxDistance, Destination, nullptr, SharedFilter))
43 {
44 OwnerComp.GetBlackboardComponent()->SetValueAsVector(MoveTargetLocation.SelectedKeyName, Destination.Location);
45 return EBTNodeResult::Succeeded;
46 }
47 }
48 return EBTNodeResult::Failed;
49}
float MaxDistance
Definition BTT_GetRandomLocation.h:27
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTT_GetRandomLocation.cpp:20
TSubclassOf< UNavigationQueryFilter > Filter
Definition BTT_GetRandomLocation.h:31

◆ GetStaticDescription()

FString UBTT_GetRandomLocation::GetStaticDescription ( ) const
overrideprotectedvirtual
52{
53 FString Description;
54 Description += FString::Printf(TEXT("\nMax Distance: %i"), FMath::RoundToInt(MaxDistance));
55 if(Filter != nullptr)
56 {
57 Description += FString::Printf(TEXT("\nFilter: %s"), *GetNameSafe(Filter.Get()));
58 }
59 else
60 {
61 Description += FString::Printf(TEXT("\nFilter: NONE"));
62 }
63 return Description;
64}

Member Data Documentation

◆ Filter

TSubclassOf<UNavigationQueryFilter> UBTT_GetRandomLocation::Filter = nullptr

Navigation Query filter used when picking the location, only picks locations reachable using this filter when assigned.

◆ MaxDistance

float UBTT_GetRandomLocation::MaxDistance = 1000.0f

Maximum distance the random location picked may be from pawn.

◆ MoveTargetLocation

FBlackboardKeySelector UBTT_GetRandomLocation::MoveTargetLocation

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