AGameModeBase::Login
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Creates and returns a new PlayerController for a player joining the server. Set ErrorMessage to a non-empty string to reject the login. This is for basic player setup; game logic belongs in PostLogin().
Caveats & Gotchas
- • The PlayerController is not fully initialized (net connection not yet established) when Login() returns. Do not call replicated functions or access PlayerState members here — use PostLogin() for that.
- • PreLogin() is called first and may reject the player before Login() is ever reached. If your rejection logic needs to fire at the earliest possible point (before bandwidth is consumed), put it in PreLogin() instead.
Signature
ENGINE_API virtual APlayerController* Login(UPlayer* NewPlayer, ENetRole InRemoteRole, const FString& Portal, const FString& Options, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| NewPlayer | UPlayer* | The UPlayer object representing this player (local or remote). | — |
| InRemoteRole | ENetRole | The net role this player controller will have on the remote machine. | — |
| Portal | const FString& | Desired portal or spawn point name specified by the client. | — |
| Options | const FString& | URL options string passed by the client (e.g. player name, spectator flags). | — |
| UniqueId | const FUniqueNetIdRepl& | Platform-specific unique identifier for the logging-in player. | — |
| ErrorMessage | FString& | Output parameter — set to a non-empty string to reject the login with that error. | — |
Return Type
APlayerController* Example
Assign players to teams on login C++
APlayerController* AMyGameMode::Login(UPlayer* NewPlayer, ENetRole InRemoteRole,
const FString& Portal, const FString& Options,
const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
{
APlayerController* PC = Super::Login(NewPlayer, InRemoteRole, Portal, Options, UniqueId, ErrorMessage);
if (PC && ErrorMessage.IsEmpty())
{
AssignPlayerToTeam(PC);
}
return PC;
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?