RealDocs

APawn::GetLocalViewingPlayerController

function Engine Blueprint Since 4.0
#include "GameFramework/Pawn.h"
Access: public Specifiers: UFUNCTIONBlueprintCallable

Description

Returns the local PlayerController that has this pawn as its ViewTarget, whether it is controlling or spectating. Returns nullptr if no local player is currently viewing this pawn.

Caveats & Gotchas

  • Unlike GetController(), this includes spectators — a local player that is observing this pawn via a spectate camera will still cause this to return a non-null value even though the pawn isn't possessed by them.
  • Returns nullptr on dedicated servers since there is no local player. Always null-check before using the result.
  • In split-screen games with multiple local players, returns the first local PlayerController that has this pawn as its ViewTarget. Behavior with multiple simultaneous viewers is not deterministic.

Signature

APlayerController* GetLocalViewingPlayerController() const

Return Type

APlayerController*

Example

Apply post-process effect only for the local viewer C++
void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (APlayerController* LocalPC = GetLocalViewingPlayerController())
	{
		// Only apply expensive screen effects for the local viewer
		ApplyScreenEffect(LocalPC);
	}
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.