Here is the photos and code
// K-B 2021
#include "UPGAIController.h"
#include "Kismet/GameplayStatics.h"
#include "BehaviorTree/BlackboardComponent.h"
void AUPGAIController::BeginPlay()
{
Super::BeginPlay();
if (AIBehavior != nullptr)
{
RunBehaviorTree(AIBehavior);
//declarations:
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
GetBlackboardComponent()->SetValueAsVector(TEXT("StartLocation"), GetPawn()->GetActorLocation());
}
}
void AUPGAIController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
//declarations:
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
if (LineOfSightTo(PlayerPawn))
{
GetBlackboardComponent()->SetValueAsVector(TEXT("PlayerLocation"), PlayerPawn->GetActorLocation());
GetBlackboardComponent()->SetValueAsVector(TEXT("LastKnownPlayerLocation"), PlayerPawn->GetActorLocation());
}
else
{
GetBlackboardComponent()->ClearValue(TEXT("PlayerLocation"));
}
}