AGameModeBase::PreLoginAsync
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Async version of `PreLogin` that allows off-thread backend calls (e.g. ban checks or entitlement verification) before accepting a connection. Must call `OnComplete` when finished.
Caveats & Gotchas
- • **You must call `OnComplete` exactly once**, even on failure or timeout. Failing to do so causes the connecting client to hang indefinitely waiting for a response, eventually timing out.
- • The base implementation calls synchronous `PreLogin` and immediately fires `OnComplete` — you only need to override this if you require a genuinely async operation. Do not override both `PreLogin` and `PreLoginAsync` unless you call `PreLogin` from your `PreLoginAsync` override.
- • If your async work can fail (e.g. the backend is unreachable), decide on a fail-open or fail-closed policy explicitly. The engine has no default timeout for the async case.
Signature
virtual void PreLoginAsync(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, const FOnPreLoginCompleteDelegate& OnComplete) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Options | const FString& | The URL options string from the connecting client. | — |
| Address | const FString& | The network address of the connecting player. | — |
| UniqueId | const FUniqueNetIdRepl& | The platform-specific unique ID of the connecting player. | — |
| OnComplete | const FOnPreLoginCompleteDelegate& | Delegate that MUST be called with the error message (empty = success) when the async check finishes. | — |
Return Type
void Example
Async ban check against a backend service C++
void AMyGameMode::PreLoginAsync(const FString& Options, const FString& Address,
const FUniqueNetIdRepl& UniqueId, const FOnPreLoginCompleteDelegate& OnComplete)
{
// Kick off async HTTP ban check
TSharedRef<IHttpRequest> Req = FHttpModule::Get().CreateRequest();
Req->SetURL(FString::Printf(TEXT("https://api.mygame.com/bans/%s"), *UniqueId.ToString()));
Req->SetVerb(TEXT("GET"));
Req->OnProcessRequestComplete().BindLambda(
[OnComplete](FHttpRequestPtr, FHttpResponsePtr Response, bool bSuccess)
{
FString Error;
if (!bSuccess || !Response.IsValid())
{
// Fail-open: allow on backend error
}
else if (Response->GetContentAsString().Contains(TEXT("banned")))
{
Error = TEXT("You are banned from this server.");
}
OnComplete.ExecuteIfBound(Error);
});
Req->ProcessRequest();
} Version History
Introduced in: 4.24
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?