メインコンテンツまでスキップ

複数の環境を設定する

Last updated on December 17, 2024

Overview

AccelByte Gaming Services (AGS) enables you to use different environments (Production, Certification, Default, and Development) within one project, meaning that you only need to build your game once. By using the AGS Game SDK, you will be able to switch environments even when your build is running.

For example, you can run and test your build in the Certification environment, and then publish your game to the Production environment, all without having to rebuild your game for each separate environment.

This guide will walk you through setting up multiple project environments.

Unreal Engine

You will need to fill in three new AccelByteSettings in DefaultEngine.ini in order to enable switching of environments.

  • For the Development environment, fill in the configuration in /Script/AccelByteUe4Sdk.AccelByteSettingsDev.
[/Script/AccelByteUe4Sdk.AccelByteSettingsDev]
ClientId=Game Client ID
ClientSecret=Game Client Secret
Namespace=Game Namespace
PublisherNamespace=Publisher Namespace
RedirectURI="http://127.0.0.1"
BaseUrl="https://dev.accelbyte.io"
IamServerUrl="https://dev.accelbyte.io/iam"
PlatformServerUrl="https://dev.accelbyte.io/platform"
LobbyServerUrl="wss://dev.accelbyte.io/lobby/"
CloudStorageServerUrl="https://dev.accelbyte.io/binary-store"
BasicServerUrl="https://dev.accelbyte.io/basic"
GameProfileServerUrl="https://dev.accelbyte.io/soc-profile"
StatisticServerUrl="https://dev.accelbyte.io/statistic"
QosManagerServerUrl="https://dev.accelbyte.io/qosm"
LeaderboardServerUrl="https://dev.accelbyte.io/leaderboard"
CloudSaveServerUrl="https://dev.accelbyte.io/cloudsave"
GameTelemetryServerUrl="https://dev.accelbyte.io/game-telemetry"
AgreementServerUrl="https://dev.accelbyte.io/agreement"
AchievementServerUrl="https://dev.accelbyte.io/achievement"
SessionBrowserServerUrl="https://dev.accelbyte.io/sessionbrowser"
UGCServerUrl="https://dev.accelbyte.io/ugc"
ReportingServerUrl="https://dev.accelbyte.io/reporting"
AppId=Your App Id
  • For the Certification environment, fill in the configuration in /Script/AccelByteUe4Sdk.AccelByteSettingsCert.
[/Script/AccelByteUe4Sdk.AccelByteSettingsCert]
ClientId=Game Client ID
ClientSecret=Game Client Secret
Namespace=Game Namespace
PublisherNamespace=Publisher Namespace
RedirectURI="http://127.0.0.1"
BaseUrl="https://cert.accelbyte.io"
IamServerUrl="https://cert.accelbyte.io/iam"
PlatformServerUrl="https://cert.accelbyte.io/platform"
LobbyServerUrl="wss://cert.accelbyte.io/lobby/"
CloudStorageServerUrl="https://cert.accelbyte.io/binary-store"
BasicServerUrl="https://cert.accelbyte.io/basic"
GameProfileServerUrl="https://cert.accelbyte.io/soc-profile"
StatisticServerUrl="https://cert.accelbyte.io/statistic"
QosManagerServerUrl="https://cert.accelbyte.io/qosm"
LeaderboardServerUrl="https://cert.accelbyte.io/leaderboard"
CloudSaveServerUrl="https://cert.accelbyte.io/cloudsave"
GameTelemetryServerUrl="https://cert.accelbyte.io/game-telemetry"
AgreementServerUrl="https://cert.accelbyte.io/agreement"
AchievementServerUrl="https://cert.accelbyte.io/achievement"
SessionBrowserServerUrl="https://cert.accelbyte.io/sessionbrowser"
UGCServerUrl="https://cert.accelbyte.io/ugc"
ReportingServerUrl="https://cert.accelbyte.io/reporting"
AppId=Your App Id
  • For the Production environment, fill in the configuration in /Script/AccelByteUe4Sdk.AccelByteSettingsProd.
[/Script/AccelByteUe4Sdk.AccelByteSettingsProd]
ClientId=Game Client ID
ClientSecret=Game Client Secret
Namespace=Game Namespace
PublisherNamespace=Publisher Namespace
RedirectURI="http://127.0.0.1"
BaseUrl="https://prod.gamingservices.accelbyte.io"
IamServerUrl="https://prod.gamingservices.accelbyte.io/iam"
PlatformServerUrl="https://prod.gamingservices.accelbyte.io/platform"
LobbyServerUrl="wss://demo.accelbyte.io/lobby/"
CloudStorageServerUrl="https://prod.gamingservices.accelbyte.io/binary-store"
BasicServerUrl="https://prod.gamingservices.accelbyte.io/basic"
GameProfileServerUrl="https://prod.gamingservices.accelbyte.io/soc-profile"
StatisticServerUrl="https://prod.gamingservices.accelbyte.io/statistic"
QosManagerServerUrl="https://prod.gamingservices.accelbyte.io/qosm"
LeaderboardServerUrl="https://prod.gamingservices.accelbyte.io/leaderboard"
CloudSaveServerUrl="https://prod.gamingservices.accelbyte.io/cloudsave"
GameTelemetryServerUrl="https://prod.gamingservices.accelbyte.io/game-telemetry"
AgreementServerUrl="https://prod.gamingservices.accelbyte.io/agreement"
AchievementServerUrl="https://prod.gamingservices.accelbyte.io/achievement"
SessionBrowserServerUrl="https://prod.gamingservices.accelbyte.io/sessionbrowser"
UGCServerUrl="https://prod.gamingservices.accelbyte.io/ugc"
ReportingServerUrl="https://dev.accelbyte.io/reporting"
AppId=Your App Id

Retrieve the OSS Online Environment

Retrieve the available Unreal OSS Online Environment to check if the game is running in the correct environment and avoid mismatching environment settings.

IOnlineSubsystem* OSS = IOnlineSubsystem::Get(PS4_SUBSYSTEM);
EOnlineEnvironment::Type OSSEnvironment = OSS->GetOnlineEnvironment();

Convert OSS Environment to AGS Settings Environment

Convert the Unreal OSS Environment enumeration to the AGS Setting Environment so you can switch between AGS Environments based on what is set in the Unreal OSS Environment. For more information on these environments, see the example enumeration in the Unreal OSS and AGS Settings environments below:

enum EOnlineEnvironment::Type
{
/** Dev environment */
Development,
/** Cert environment */
Certification,
/** Prod environment */
Production,
/** Not determined yet */
Unknown
};
enum class ESettingsEnvironment : uint8
{
/** Dev environment settings */
Development,
/** Cert environment settings */
Certification,
/** Prod environment settings */
Production,
/** Default environment settings */
Default
};

Convert the Unreal OSS Environment enumeration to the AGS Setting Environment using the following function:

ESettingsEnvironment ConvertOSSEnvtoABEnv (const EOnlineEnvironment::Type& Environment)
{
switch (Environment)
{
case EOnlineEnvironment::Type::Development :
return ESettingsEnvironment::Development;

case EOnlineEnvironment::Type::Certification:
return ESettingsEnvironment::Certification;

case EOnlineEnvironment::Type::Production:
return ESettingsEnvironment::Production;

case EOnlineEnvironment::Type::Unknown:
default:
return ESettingsEnvironment::Default;
}
}

Call Switch Environment function

In order to switch between environments, make sure to use AccelByteUe4SdkModule.h and call the IAccelByteUe4SdkModuleInterface::Get().SetEnvironment(ABEnvironment) function, as seen in the example below:

IOnlineSubsystem* OSS = IOnlineSubsystem::Get(PS4_SUBSYSTEM);
EOnlineEnvironment::Type OSSEnvironment = OSS->GetOnlineEnvironment();

ESettingsEnvironment ABEnvironment = ConvertOSSEnvtoABEnv(OSSEnvironment);

IAccelByteUe4SdkModuleInterface::Get().SetEnvironment(ABEnvironment);

After you call IAccelByteUe4SdkModuleInterface::Get().SetEnvironment(ABEnvironment), the SDK will load the respective AGS Environment Settings that you have previously set. You will now be able to switch between AGS Environments.

Unity

Follow these steps to enable environment switching in Unity.

Set up the configuration files

The configs are stored in JSON format in the ProjectName/Assets/Resources folder. The configurations are separated into two files: OAuthConfig, which contains ClientId and ClientSecret, and Config, which contains service URLs and other additional configurations.

For the Client-side SDK, the configuration can be set from AccelByte's config editor. You can do this by navigating to AccelByte > Edit Settings and filling out these required fields:

  1. Base Url
  2. Redirect Uri (Default: http://127.0.0.1)
  3. Namespace
  4. Client Id
  5. Client Secret

Press Save to store the config. The editor will auto-generate AccelByteSDKOAuthConfig.json and AccelByteSDKConfig.json inside Resources directory.

For the Server-side SDK, configure each the files below with the code that follows them.

  • AccelByteServerSDKOAuthConfig.json for the OAuthConfig file:
{
"Development": {
"ClientId": "",
"ClientSecret": ""
},
"Certification": {
"ClientId": "",
"ClientSecret": ""
},
"Production": {
"ClientId": "",
"ClientSecret": ""
},
"Default": {
"ClientId": "",
"ClientSecret": ""
}
}
  • AccelByteServerSDKConfig.json for the Config file:
{
"Development": {
"Namespace": "Dev",
"BaseUrl": "",
"RedirectUri": "http://127.0.0.1"
},
"Certification": {
"Namespace": "Cert",
"BaseUrl": "",
"RedirectUri": "http://127.0.0.1"
},
"Production": {
"Namespace": "Prod",
"BaseUrl": "",
"RedirectUri": "http://127.0.0.1"
},
"Default": {
"Namespace": "Default",
"BaseUrl": "",
"RedirectUri": "http://127.0.0.1"
}
}

Change environments

You can change the active environment for both the Client- and Server-side SDK using the following code:

AccelByte.Core.AccelByteSDK.Environment.Set(SettingsEnvironment.Production);

You can then use environmentChanged to receive a callback for every successful environment change.

AccelByte.Core.AccelByteSDK.Environment.OnEnvironmentChangedV2 += (SettingsEnvironment changedFrom, SettingsEnvironment changedTo) =>
{
Debug.Log($"Environment changed from {changedFrom} to {changedTo}");
};

You can retrieve the active environment information using the following code:

SettingsEnvironment activeServerEnvironment = AccelByte.Core.AccelByteSDK.Environment.Current;
ヒント

AccelByte recommends switching the environment before any users log in to prevent unexpected behavior or potential code issues.