Are there any downsides to caching the PlayerPawn reference in BeginPlay() as opposed to searching for the reference every frame?
in ShooterAIController.h
private:
UPROPERTY(VisibleAnywhere)
APawn* PlayerPawn;
in ShooterAIController.cpp
void AShooterAIController::BeginPlay()
{
Super::BeginPlay();
PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
SetFocus(PlayerPawn);
}
void AShooterAIController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if(LineOfSightTo(PlayerPawn))
{
SetFocus(PlayerPawn);
MoveToActor(PlayerPawn, 2);
} else
{
ClearFocus(EAIFocusPriority::Gameplay);
StopMovement();
}
}