31{
33 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
34 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Services);
35
36 Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
37 FBTSCheckLineOfSightMemory* SelectTargetMemory = reinterpret_cast<FBTSCheckLineOfSightMemory*>(NodeMemory);
38 if(SelectTargetMemory == nullptr){return;}
39 SelectTargetMemory->bHasLineOfSight = false;
40 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
41 if(BlackboardComp != nullptr)
42 {
43 SelectTargetMemory->TargetActor = Cast<AActor>(BlackboardComp->GetValueAsObject(
TargetActor.SelectedKeyName));
44 }
45 if(SelectTargetMemory->TargetActor == nullptr){return;}
46 if(OwnerComp.GetAIOwner() ==
nullptr && OwnerComp.GetAIOwner()->GetPawn() ==
nullptr){UE_LOG(LogAIToolKit,
Error, TEXT(
"AI Owner NULL in Check Line Of Sight"))return;}
48 if(AIActions != nullptr)
49 {
51 for(const auto Object : PerceivedObjects)
52 {
53 if(SelectTargetMemory->TargetActor == Object)
54 {
55 FVector EyeLocation;
56 FRotator EyeRotation;
57 TArray<AActor*> ActorsToIgnore;
58 ActorsToIgnore.Add(SelectTargetMemory->TargetActor);
59 ActorsToIgnore.Add(OwnerComp.GetAIOwner()->GetPawn());
61 OwnerComp.GetAIOwner()->GetPawn()->GetActorEyesViewPoint(EyeLocation, EyeRotation);
62 bool bHit = UKismetSystemLibrary::LineTraceSingle(this,EyeLocation,SelectTargetMemory->TargetActor->GetActorLocation(),
63 UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel4),
65 true, FLinearColor::Blue,
67 SelectTargetMemory->bHasLineOfSight = bHit == false;
69 {
71 }
72 }
73 else
74 {
76 {
78 }
79 }
80 }
81 }
82 if(BlackboardComp != nullptr)
83 {
84 BlackboardComp->SetValueAsBool(
bHasLineOfSightToEnemy.SelectedKeyName, SelectTargetMemory->bHasLineOfSight);
85 }
86}
Definition AIActionsInterface.h:20
virtual TArray< AActor * > GetPerceivedObjects(const TArray< EAIStimuliType > Filters) const =0
virtual void TickNode(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
Definition BTS_CheckLineOfSight.cpp:30
float LineDrawTime
Definition BTS_CheckLineOfSight.h:43
float PointSize
Definition BTS_CheckLineOfSight.h:41
bool bDebugAllObjects
Definition BTS_CheckLineOfSight.h:39
TArray< EAIStimuliType > FilterTypes
Definition BTS_CheckLineOfSight.h:34
FBlackboardKeySelector bHasLineOfSightToEnemy
Definition BTS_CheckLineOfSight.h:32
FColor ObjectPointColor
Definition BTS_CheckLineOfSight.h:45
FColor TargetPointColor
Definition BTS_CheckLineOfSight.h:47
static EDrawDebugTrace::Type GetDrawDebugType(const bool bDebuggingMode)
Definition BaseHelpersBPLib.cpp:910