ゲームで複数のレジストリのサポートを有効にする (Unreal)
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:
Use Find all to locate all the
FRegistry::*
classes in your project. Then, for singleton classes, replaceFRegistry::
withFMultiRegistry::Ge
.WARNINGDo not change
FRegistry::Settings
,FRegistry::Credentials
, orFRegistry::HttpRetryScheduler
.Check that the compilation still runs after you have renamed it. If not, undo your previous changes and repeat these steps.
- API Client
- Previous Usage
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);
}));
FRegistry::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:
Use Find all to locate all the
FRegistry::*
singleton classes in your project and replaceFRegistry::*
withFMultiRegistry::GetServerApiClient()->
.WARNINGDo not change
FRegistry::ServerSettings
.
- API Client
- Previous Usage
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);
}));
FRegistry::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:
Check the
DefaultEngine.ini
configuration file. Ensure thatbMultipleLocalUsersEnabled
istrue
if there are multiple local players in a single game process.[OnlineSubsystemAccelByte]
bEnabled=true
bAutoLobbyConnectAfterLoginSuccess=false
bMultipleLocalUsersEnabled=trueLog in the user using AGS Online Identity Interface, which is used for player authentication and profiles.
After logging in, make note of the
LocalUserNum
that is passed.virtual bool Login(int32 LocalUserNum, const FOnlineAccountCredentials& AccountCredentials) override;
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.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);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.
Your UI implementation may vary depending on your game and the login method you choose.
To create this flow, follow these steps:
Call
Get Api Client
.On the
Return Value
, call the API you want to use. In this case, it will be theUser
API.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.