RealDocs

APawn::OnRep_PlayerState

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

Description

Replication notification called on clients when the PlayerState pointer changes. Override to react when the pawn's associated player state arrives or is cleared (e.g., to populate a nameplate or scoreboard entry).

Caveats & Gotchas

  • PlayerState replication is not guaranteed to arrive before or after possession — in net games the PlayerState may still be null when OnRep_Controller fires. Always guard accesses to PlayerState with a null check and handle the case where it arrives late.
  • The notification fires both when PlayerState is set (possession) and when it is cleared (un-possession/disconnect). Check whether the new value is null to distinguish the two cases.
  • Call Super::OnRep_PlayerState() to preserve any base engine logic tied to this notification.

Signature

virtual void OnRep_PlayerState()

Return Type

void

Example

Update a nameplate when player state arrives C++
void AMyPawn::OnRep_PlayerState()
{
	Super::OnRep_PlayerState();
	if (PlayerState)
	{
		UpdateNameplateText(PlayerState->GetPlayerName());
	}
}

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.