AGameModeBase::ChangeName
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtualUFUNCTIONBlueprintCallable
Description
Assigns or changes a player's name on the server, then broadcasts the change via K2_OnChangeName. Called automatically during login for the initial name, and can be called at runtime to rename a player.
Caveats & Gotchas
- • Only valid to call on the server — calling from a client will have no effect because GameMode only exists on the server.
- • After changing the name, the new name is replicated through APlayerState::PlayerName, so clients will see it once the PlayerState replicates. There may be a one-frame delay before clients see the update.
- • bNameChange is false during the initial login assignment; if you gate logic on name-change events (e.g., broadcast a chat message), check this flag to avoid firing on the initial assignment.
Signature
ENGINE_API virtual void ChangeName(AController* Controller, const FString& NewName, bool bNameChange); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Controller | AController* | The controller of the player whose name should be changed. | — |
| NewName | const FString& | The new name to assign to the player. | — |
| bNameChange | bool | True if this is a name change for an already-named player; false if this is the initial name assignment. | — |
Return Type
void Example
Rename a player at runtime from the server C++
// Inside server-side game logic (GameMode or similar)
void AMyGameMode::RenamePlayer(APlayerController* PC, const FString& NewName)
{
if (PC && !NewName.IsEmpty())
{
ChangeName(PC, NewName, true);
}
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?