RealDocs

APlayerState::OnRep_PlayerId

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

Description

Replication notification called on clients when the PlayerId property is first replicated or changes. The base implementation does nothing; override if your game displays or keys data off the numeric player ID.

Caveats & Gotchas

  • PlayerId is an incrementing integer assigned by the GameMode on the server, not the player's online platform ID. For platform-level identity, listen to OnRep_UniqueId instead.
  • Because PlayerId is replicated via ReplicatedUsing, the property is guaranteed to have its new value when this function executes. However, other replicated properties on the same PlayerState may not yet be up-to-date at this point.
  • The base APlayerState implementation of OnRep_PlayerId is empty. Calling Super::OnRep_PlayerId() is a no-op but is still good practice for future subclass chains.

Signature

ENGINE_API virtual void OnRep_PlayerId();

Return Type

void

Example

Map numeric player ID to an initial team slot C++
void AMyPlayerState::OnRep_PlayerId()
{
	Super::OnRep_PlayerId();
	// PlayerId is used as the initial team assignment index in this game
	TeamIndex = GetPlayerId() % NumTeams;
	UpdateTeamIndicator();
}

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.