RealDocs

APawn::SetPlayerState

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

Description

Establishes or clears the bidirectional link between this pawn and a PlayerState, keeping both objects' internal references in sync. Called by the framework during possession; rarely needed in gameplay code.

Caveats & Gotchas

  • This is an internal framework method — calling it manually will bypass the OnPlayerStateChanged callback and can desync the PlayerState's pawn pointer. Use AController::Possess() to trigger possession through the correct path.
  • Only call this on the server; PlayerState replication handles clients automatically. Calling it on a client will silently set a local reference that will be overwritten when replication arrives.

Signature

void SetPlayerState(APlayerState* NewPlayerState)

Parameters

Name Type Description Default
NewPlayerState APlayerState* The new PlayerState to associate with this pawn. Pass null to clear the association.

Return Type

void

Example

Engine-internal possession path (for reference) C++
// Typically called internally by PossessedBy; shown here for understanding:
void AMyGameMode::HandlePossession(APawn* Pawn, APlayerController* PC)
{
	if (PC && PC->PlayerState)
	{
		Pawn->SetPlayerState(PC->PlayerState);
	}
}

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.