Skip to main content

Enable multiple registries support in your game (Unreal)

Last updated on December 17, 2024

Overview

The AccelByte Gaming Services (AGS) Multiple Registries feature supports multiplayer in a single game process. This article walks you through how to migrate your Unreal Engine game from a singleton-based registry to multiple registries, enabling it to support multiple registries.

Game client

The FApiClient game client is a class that can be created from FMultiRegistry. You must prepare a key to construct the FApiClient. The key represents the managed user, or acts as an identifier. To handle several users at the same time, you can use this method to create multiple keys or leave it empty to use the default user if the game has only one player in one game process or executable.

To migrate FRegistry to FMultiRegistry, follow these steps:

  1. Use Find all to locate all the FRegistry::* classes in your project. Then, for singleton classes, replace FRegistry:: with FMultiRegistry::Ge.

    WARNING

    Do not change FRegistry::Settings, FRegistry::Credentials, or FRegistry::HttpRetryScheduler.

  2. Check that the compilation still runs after you have renamed it. If not, undo your previous changes and repeat these steps.

FMultiRegistry::GetApiClient()->User.LoginWithUsername(
TEXT("user+a@example.com"),
TEXT("Password321"),
FVoidHandler::CreateWeakLambda(this, [this]()
{
UE_LOG(LogTemp, Log, TEXT("Login successful"));
}), FCustomErrorHandler::CreateWeakLambda(this, [](int32 ErrorCode, const FString& ErrorMessage, const FJsonObject& ErrorObject)
{
UE_LOG(LogTemp, Error, TEXT("Login Failed : %d, %s"), ErrorCode, *ErrorMessage);
}));

Game server

To migrate from FRegistry to FMultiRegistry, follow these steps:

  1. Use Find all to locate all the FRegistry::* singleton classes in your project and replace FRegistry::* with FMultiRegistry::GetServerApiClient()->.

    WARNING

    Do not change FRegistry::ServerSettings.

auto ServerApiClient = FMultiRegistry::GetServerApiClient();

ServerApiClient->ServerOauth2.LoginWithClientCredentials(FVoidHandler::CreateWeakLambda(this, [this]()
{
UE_LOG(LogTemp, Log, TEXT("Login With Credentials success"));
}), FErrorHandler::CreateWeakLambda(this, [this](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Error, TEXT("Login With Credentials failed, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Use the AGS OSS with the client SDKs

To get an ApiClient if your game is using the AGS Online Subsystem (OSS) to handle logins, follow these steps:

  1. Check the DefaultEngine.ini configuration file. Ensure that bMultipleLocalUsersEnabled is true if there are multiple local players in a single game process.

    [OnlineSubsystemAccelByte]
    bEnabled=true
    bAutoLobbyConnectAfterLoginSuccess=false
    bMultipleLocalUsersEnabled=true
  2. Log in the user using AGS Online Identity Interface, which is used for player authentication and profiles.

  3. After logging in, make note of the LocalUserNum that is passed.

    virtual bool Login(int32 LocalUserNum, const FOnlineAccountCredentials& AccountCredentials) override;
  4. Use [OnLoginCompleteDelegates](https://docs.unrealengine.com/4.27/en-US/API/Plugins/OnlineSubsystem/Interfaces/IOnlineIdentity/OnLoginCompleteDelegates/index.html) to find the login result from the identity interface.

  5. After the user has been logged in, call the following function from the AGS Identity Interface:

    IOnlineSubsystem* SubsystemAB = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
    const FOnlineIdentityAccelBytePtr IdentityPtr = StaticCastSharedPtr<FOnlineIdentityAccelByte>(SubsystemAB->GetIdentityInterface());
    FApiClientPtr ApiClient = IdentityPtr->GetApiClient(in32 LocalUserNum);
  6. Pass the same LocalUserNum that was used for the login. FApiClientPtr will be returned and can be used for various API calls by the specified user.

Blueprint implementation

The following blueprint diagram shows the flow you need to use an API in Unreal Engine to call the Login with Username API.

note

Your UI implementation may vary depending on your game and the login method you choose.

Unreal Blueprint showing flow to use an API to call Login with Username

To create this flow, follow these steps:

  1. Call Get Api Client.

  2. On the Return Value, call the API you want to use. In this case, it will be the User API.

  3. Once this API has been successfully called, you can call the Login with Username API.

Once the Login with Username API has been successfully called, your setup is complete.