AGameModeBase::PreLogin
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Called before `Login` to accept or reject an incoming connection. Set `ErrorMessage` to a non-empty string to deny the player with that reason.
Caveats & Gotchas
- • There may be significant time between `PreLogin` and the subsequent `Login` call — do not store per-connection state that is keyed on the connection object, as conditions may change.
- • If you need to perform an async check (e.g. backend ban lookup), override `PreLoginAsync` instead. The synchronous `PreLogin` blocks the game thread for the duration of the call.
- • The `FGameModeEvents::GameModePreLoginEvent` global delegate is broadcast inside the base implementation. Overriding without calling `Super` will prevent plugins and online subsystems from running their own pre-login checks.
Signature
virtual void PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Options | const FString& | The URL options passed by the connecting client (e.g. name, password). | — |
| Address | const FString& | The network address of the connecting player. | — |
| UniqueId | const FUniqueNetIdRepl& | The platform-specific unique ID of the connecting player. | — |
| ErrorMessage | FString& | Output error message. Set to a non-empty string to reject the player. | — |
Return Type
void Example
Reject players who lack a required password C++
void AMyGameMode::PreLogin(const FString& Options, const FString& Address,
const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
{
Super::PreLogin(Options, Address, UniqueId, ErrorMessage);
// If super already rejected, don't overwrite the message
if (!ErrorMessage.IsEmpty()) return;
FString Password = UGameplayStatics::ParseOption(Options, TEXT("Password"));
if (Password != ServerPassword)
{
ErrorMessage = TEXT("Incorrect server password.");
}
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?