RealDocs

APlayerState::OnRep_PlayerName

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

Description

Replication notification called on clients when the PlayerNamePrivate property is updated from the server. The base implementation broadcasts the player-entered/name-changed system message via HandleWelcomeMessage.

Caveats & Gotchas

  • The base implementation calls HandleWelcomeMessage(), which broadcasts the 'X has joined' or 'X changed name to Y' chat message to all clients. If you override without calling Super, name-change announcements will not appear.
  • OldNamePrivate is updated before this fires on the client if the name changed. You can call GetOldPlayerName() to retrieve it for a delta display.
  • This fires on the owning client as well as other clients. If you update a name display widget here, make sure the widget is valid before accessing it.

Signature

ENGINE_API virtual void OnRep_PlayerName();

Return Type

void

Example

Update a world-space name tag on name replication C++
void AMyPlayerState::OnRep_PlayerName()
{
	Super::OnRep_PlayerName(); // Broadcasts join/rename message
	if (APawn* MyPawn = GetPawn())
	{
		if (UMyNameTagComponent* Tag = MyPawn->FindComponentByClass<UMyNameTagComponent>())
		{
			Tag->SetName(GetPlayerName());
		}
	}
}

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.