RealDocs

APlayerState::SetPlayerId

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

Description

Assigns the player's session-local numeric ID and triggers replication. Typically called by the GameMode during player login; rarely needed in game code.

Caveats & Gotchas

  • This is normally called internally by the engine during InitNewPlayer — overriding or calling it manually risks duplicate IDs within the session unless you manage ID assignment yourself.
  • Server-only; setting from a client has no networked effect.

Signature

void SetPlayerId(const int32 NewId)

Parameters

Name Type Description Default
NewId const int32 The numeric player ID to assign.

Return Type

void

Example

Assign a deterministic player ID in a custom GameMode C++
void AMyGameMode::InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId, const FString& Options, const FString& Portal)
{
    Super::InitNewPlayer(NewPlayerController, UniqueId, Options, Portal);
    // Override the auto-assigned ID with a deterministic team-based value
    if (APlayerState* PS = NewPlayerController->PlayerState)
    {
        PS->SetPlayerId(GetNextTeamSlotId());
    }
}

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.