RealDocs

APlayerState::SetPlayerName

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

Description

Sets the player's name and triggers replication to all clients, then broadcasts the name-change message using EngineMessageClass.

Caveats & Gotchas

  • Must be called on the server. The name is replicated via PlayerNamePrivate with ReplicatedUsing=OnRep_PlayerName — calling this on a client will only change the local value without notifying other players.
  • This triggers the EngineMessageClass broadcast immediately — if you need to set the name silently (e.g. during initialization before the match starts), use SetPlayerNameInternal instead.

Signature

ENGINE_API virtual void SetPlayerName(const FString& S);

Parameters

Name Type Description Default
S const FString& The new player name to set.

Return Type

void

Example

Rename a player on the server C++
void AMyGameMode::RenamePlayer(APlayerController* PC, const FString& NewName)
{
    if (HasAuthority() && PC && PC->PlayerState)
    {
        PC->PlayerState->SetPlayerName(NewName);
    }
}

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.