text: #include "BTService_PlayerLocationIfSeen.h"
  
  #include "BehaviorTree/BlackboardComponent.h"
  #include "Kismet/GameplayStatics.h"
  #include "GameFramework/Pawn.h"
  #include "AIController.h"
  
  UBTService_PlayerLocationIfSeen::UBTService_PlayerLocationIfSeen() 
  {
      NodeName = TEXT("Update Player Location If Seen");
  }
  
  void UBTService_PlayerLocationIfSeen::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) 
  {
      Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
  
      if (APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0))
      {
          if (OwnerComp.GetAIOwner()->LineOfSightTo(PlayerPawn))
          {
              OwnerComp.GetBlackboardComponent()->SetValueAsObject(GetSelectedBlackboardKey(), PlayerPawn);
          }
          else
          {
              OwnerComp.GetBlackboardComponent()->ClearValue(GetSelectedBlackboardKey());
          }
      }
  }
  