APlayerState::GetPlayerNameCustom
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: virtualENGINE_API
Description
Extension point for returning a custom player name from a source other than the replicated PlayerNamePrivate field. Only called when bUseCustomPlayerNames is set to true.
Caveats & Gotchas
- • This is never called unless bUseCustomPlayerNames is explicitly set to true in your PlayerState. You must set that flag in your constructor or PostInitializeComponents alongside overriding this function.
- • The return value is not automatically replicated — if your custom name source changes, you are responsible for propagating the change to clients (e.g. via a replicated property or RPC).
Signature
ENGINE_API virtual FString GetPlayerNameCustom() const; Return Type
FString Example
Return name from custom player data component C++
AMyPlayerState::AMyPlayerState(const FObjectInitializer& OI)
: Super(OI)
{
bUseCustomPlayerNames = true;
}
FString AMyPlayerState::GetPlayerNameCustom() const
{
if (UMyPlayerDataComponent* Data = GetComponentByClass<UMyPlayerDataComponent>())
{
return Data->GetDisplayName();
}
return Super::GetPlayerNameCustom();
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?