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

#include <BTTask_PredictLocation.h>

Inheritance diagram for UBTTask_PredictLocation:

Classes

struct  FBTTaskPredictLocationMemory
 

Public Member Functions

 UBTTask_PredictLocation ()
 

Public Attributes

bool bUseCustomPredictionTime = false
 
float PredictionTime = 0.5f
 
FBlackboardKeySelector TargetEnemy
 
FBlackboardKeySelector TargetFireLocation
 
bool bUseCustomDelayDuration = false
 
float DelayDuration = 0.1f
 

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

The UBTTask_PredictLocation class is a behavior tree task node used to predict the location of a target enemy. It inherits from UBTTaskNode.

It has the following public variables:

  • bUseCustomPredictionTime: a boolean indicating whether to use a custom prediction time (default is false)
  • PredictionTime: a float indicating the prediction time for target enemy's location (default is 0.5)
  • TargetEnemy: a FBlackboardKeySelector representing the key for the target enemy
  • TargetFireLocation: a FBlackboardKeySelector representing the key for the target fire location
  • bUseCustomDelayDuration: a boolean indicating whether to use a custom delay duration (default is false)
  • DelayDuration: a float indicating the delay duration (default is 0.1)

It has the following protected functions:

  • ExecuteTask: a function called to execute the task
  • AbortTask: a function called to abort the task
  • TickTask: a function called every frame to update the task

It has the following private struct:

See also
UBTTaskNode

Constructor & Destructor Documentation

◆ UBTTask_PredictLocation()

UBTTask_PredictLocation::UBTTask_PredictLocation ( )
17{
18 NodeName = TEXT("Predict Location");
19 INIT_TASK_NODE_NOTIFY_FLAGS();
20}

Member Function Documentation

◆ AbortTask()

EBTNodeResult::Type UBTTask_PredictLocation::AbortTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
51{
52 return EBTNodeResult::Aborted;
53}

◆ ExecuteTask()

EBTNodeResult::Type UBTTask_PredictLocation::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
23{
24 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_PredictLocation::ExecuteTask);
25 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
26 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
27 FBTTaskPredictLocationMemory* PredictLocationMemory = reinterpret_cast<FBTTaskPredictLocationMemory*>(NodeMemory);
28 if(PredictLocationMemory == nullptr){return EBTNodeResult::Failed;}
29
31 {
32 DelayDuration = GetWorld()->GetDeltaSeconds();
33 }
34 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
35 if(BlackboardComp != nullptr)
36 {
37 PredictLocationMemory->TargetActor = Cast<AActor>(BlackboardComp->GetValueAsObject(TargetEnemy.SelectedKeyName));
38 if(PredictLocationMemory->TargetActor != nullptr)
39 {
40 IAIActionsInterface* AIActions = Cast<IAIActionsInterface>(OwnerComp.GetAIOwner());
41 if(AIActions != nullptr)
42 {
43 AIActions->PredictLocation(PredictLocationMemory->TargetActor);
44 }
45 }
46 }
47 return EBTNodeResult::InProgress;
48}
Definition AIActionsInterface.h:20
virtual FVector PredictLocation(AActor *TargetActor)=0
FBlackboardKeySelector TargetEnemy
Definition BTTask_PredictLocation.h:46
float DelayDuration
Definition BTTask_PredictLocation.h:52
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_PredictLocation.cpp:22
bool bUseCustomDelayDuration
Definition BTTask_PredictLocation.h:50

◆ GetInstanceMemorySize()

uint16 UBTTask_PredictLocation::GetInstanceMemorySize ( ) const
overrideprotectedvirtual
94{
95 return sizeof(FBTTaskPredictLocationMemory);
96}

◆ GetStaticDescription()

FString UBTTask_PredictLocation::GetStaticDescription ( ) const
overrideprotectedvirtual
99{
100 FString Description;
102 {
103 Description += FString::Printf(TEXT("\nCustom Prediction Time: %i"), FMath::RoundToInt(PredictionTime));
104 }
106 {
107 Description += FString::Printf(TEXT("\nCustom Prediction Time: %i"), FMath::RoundToInt(PredictionTime));
108 }
109 if(TargetEnemy.SelectedKeyName.IsValid())
110 {
111 Description += FString::Printf(TEXT("\nTarget Enemy: %s"), *TargetEnemy.SelectedKeyName.ToString());
112 }
113 else
114 {
115 Description += TEXT("\nTarget Enemy: None");
116 }
117 if(TargetFireLocation.SelectedKeyName.IsValid())
118 {
119 Description += FString::Printf(TEXT("\nTarget Fire Location: %s"), *TargetFireLocation.SelectedKeyName.ToString());
120 }
121 else
122 {
123 Description += TEXT("\nTarget Fire Location: None");
124 }
125 return Description;
126}
bool bUseCustomPredictionTime
Definition BTTask_PredictLocation.h:42
FBlackboardKeySelector TargetFireLocation
Definition BTTask_PredictLocation.h:48
float PredictionTime
Definition BTTask_PredictLocation.h:44

◆ TickTask()

void UBTTask_PredictLocation::TickTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory,
float DeltaSeconds )
overrideprotectedvirtual
56{
57 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_PredictLocation::TickTask);
58 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
59 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
60 FBTTaskPredictLocationMemory* PredictLocationMemory = reinterpret_cast<FBTTaskPredictLocationMemory*>(NodeMemory);
61 if(PredictLocationMemory == nullptr){FinishLatentTask(OwnerComp, EBTNodeResult::Failed);}
62 if(GetWorld()->GetTimeSeconds() - PredictLocationMemory->StartTime >= DelayDuration)
63 {
64 FActorPerceptionBlueprintInfo SenseInfo;
65 if(OwnerComp.GetAIOwner() != nullptr && OwnerComp.GetAIOwner()->GetAIPerceptionComponent() != nullptr && PredictLocationMemory->TargetActor != nullptr)
66 {
67 const bool bSuccess = OwnerComp.GetAIOwner()->GetAIPerceptionComponent()->GetActorsPerception(PredictLocationMemory->TargetActor, SenseInfo);
68 if(bSuccess)
69 {
70 FAIStimulus PredictionInfo;
71 for(const auto Info : SenseInfo.LastSensedStimuli)
72 {
74 {
75 PredictionInfo = Info;
76 break;
77 }
78 }
79 if(PredictionInfo.IsValid())
80 {
81 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
82 if(BlackboardComp != nullptr)
83 {
84 BlackboardComp->SetValueAsVector(TargetFireLocation.SelectedKeyName, PredictionInfo.StimulusLocation);
85 }
86 }
87 }
88 }
89 FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
90 }
91}
static EAISense GetSenseFromStimulus(const FAIStimulus &Stimulus)
Definition AIBPLib.cpp:21
virtual void TickTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
Definition BTTask_PredictLocation.cpp:55

Member Data Documentation

◆ bUseCustomDelayDuration

bool UBTTask_PredictLocation::bUseCustomDelayDuration = false

◆ bUseCustomPredictionTime

bool UBTTask_PredictLocation::bUseCustomPredictionTime = false

◆ DelayDuration

float UBTTask_PredictLocation::DelayDuration = 0.1f

◆ PredictionTime

float UBTTask_PredictLocation::PredictionTime = 0.5f

◆ TargetEnemy

FBlackboardKeySelector UBTTask_PredictLocation::TargetEnemy

◆ TargetFireLocation

FBlackboardKeySelector UBTTask_PredictLocation::TargetFireLocation

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