RealDocs

APlayerState::GetOldPlayerName

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

Description

Returns the player's previous name, saved before the most recent name change. Used client-side to detect and announce name changes.

Caveats & Gotchas

  • OldNamePrivate is not replicated — it is only populated on the client when OnRep_PlayerName fires and the name actually changes. It will be empty on the server and on clients that haven't received a name change yet.
  • On the server, the old name is never stored; SetPlayerName immediately overwrites PlayerNamePrivate. If you need the old server-side name, read it before calling SetPlayerName.

Signature

ENGINE_API virtual FString GetOldPlayerName() const;

Return Type

FString

Example

Show name change notification on client C++
void AMyPlayerState::OnRep_PlayerName()
{
    Super::OnRep_PlayerName();
    FString OldName = GetOldPlayerName();
    FString NewName = GetPlayerName();
    if (!OldName.IsEmpty() && OldName != NewName)
    {
        AMyHUD::ShowRenameNotification(OldName, 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.