APlayerState::GetPlayerName
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: UFUNCTIONBlueprintPureENGINE_API
Description
Returns the current player name. If bUseCustomPlayerNames is set on this PlayerState, delegates to GetPlayerNameCustom() instead of returning the stored name directly.
Caveats & Gotchas
- • If bUseCustomPlayerNames is true, this calls GetPlayerNameCustom() every invocation — avoid calling it in tight loops without caching the result if your custom implementation has any cost.
- • The name is replicated, but there is a brief window after a name change where clients may still see the old name. Use OnRep_PlayerName to reliably react to name changes on clients.
Signature
ENGINE_API FString GetPlayerName() const; Return Type
FString Example
Display player name on HUD C++
FText AMyHUD::GetLocalPlayerNameText() const
{
if (APlayerState* PS = GetOwningPlayerController()->PlayerState)
{
return FText::FromString(PS->GetPlayerName());
}
return FText::GetEmpty();
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?