Skip to main content

Set Up Multiple Environments

Last updated on

Overview

AccelByte Cloud enables you to use different environments such as Production, Certification, Default, and Development, within one single project, meaning that you only need to build your game once. By using our 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.

Unreal Engine

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

  • For the Dev 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 Cert 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 Prod 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://demo.accelbyte.io"
    IamServerUrl="https://demo.accelbyte.io/iam"
    PlatformServerUrl="https://demo.accelbyte.io/platform"
    LobbyServerUrl="wss://demo.accelbyte.io/lobby/"
    CloudStorageServerUrl="https://demo.accelbyte.io/binary-store"
    BasicServerUrl="https://demo.accelbyte.io/basic"
    GameProfileServerUrl="https://demo.accelbyte.io/soc-profile"
    StatisticServerUrl="https://demo.accelbyte.io/statistic"
    QosManagerServerUrl="https://demo.accelbyte.io/qosm"
    LeaderboardServerUrl="https://demo.accelbyte.io/leaderboard"
    CloudSaveServerUrl="https://demo.accelbyte.io/cloudsave"
    GameTelemetryServerUrl="https://demo.accelbyte.io/game-telemetry"
    AgreementServerUrl="https://demo.accelbyte.io/agreement"
    AchievementServerUrl="https://demo.accelbyte.io/achievement"
    SessionBrowserServerUrl="https://demo.accelbyte.io/sessionbrowser"
    UGCServerUrl="https://demo.accelbyte.io/ugc"
    ReportingServerUrl="https://dev.accelbyte.io/reporting"
    AppId=Your App Id

Retrieve Unreal OSS Online Environment

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

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

Convert Unreal OSS Environment to AB Settings Environment

Convert the Unreal OSS Environment enumeration to the AB Setting Environment so you can switch between AB 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 AB Settings environments below:

  • EOnlineEnvironment::Type enum from OSS

    enum EOnlineEnvironment::Type
    {
    /** Dev environment */
    Development,
    /** Cert environment */
    Certification,
    /** Prod environment */
    Production,
    /** Not determined yet */
    Unknown
    };
  • ESettingsEnvironment enum from ABSettings

    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 AB 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 AccelByte Cloud Environment Settings that you have previously set. You will now be able to switch between AccelByte Cloud Environments.

Unity

Set Up the Configuration Files

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

For the Client-side SDK, fill in the following configuration in these files:

  • AccelByteSDKOAuthConfig.json for the OAuthConfig file

    {
    "Development": {
    "ClientId": "",
    "ClientSecret": ""
    },
    "Certification": {
    "ClientId": "",
    "ClientSecret": ""
    },
    "Production": {
    "ClientId": "",
    "ClientSecret": ""
    },
    "Default": {
    "ClientId": "",
    "ClientSecret": ""
    }
    }
  • AccelByteSDKConfig.json for the Config file

    {
    "Development": {
    "Namespace": "Dev",
    "UsePlayerPrefs": true,
    "EnableDebugLog": true,
    "DebugLogFilter": "Log",
    "BaseUrl": "",
    "RedirectUri": "http://127.0.0.1",
    "AppId": "",
    "PublisherNamespace": ""
    },
    "Certification": {
    "Namespace": "Cert",
    "UsePlayerPrefs": false,
    "EnableDebugLog": false,
    "DebugLogFilter": "Log",
    "BaseUrl": "",
    "RedirectUri": "http://127.0.0.1",
    "AppId": "",
    "PublisherNamespace": ""
    },
    "Production": {
    "Namespace": "Prod",
    "UsePlayerPrefs": false,
    "EnableDebugLog": false,
    "DebugLogFilter": "Log",
    "BaseUrl": "",
    "RedirectUri": "http://127.0.0.1",
    "AppId": "",
    "PublisherNamespace": ""
    },
    "Default": {
    "Namespace": "Default",
    "UsePlayerPrefs": true,
    "EnableDebugLog": true,
    "DebugLogFilter": "Log",
    "BaseUrl": "",
    "RedirectUri": "http://127.0.0.1",
    "AppId": "",
    "PublisherNamespace": ""
    }
    }

For the Server-side SDK fill in the following configuration in these files:

  • 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 in the Client-side SDK using the following code:

AccelBytePlugin.SetEnvironment(SettingsEnvironment.Production);

You can change the active environment in the Server-side SDK using the following code:

AccelByteServerPlugin.SetEnvironment(SettingsEnvironment.Production);

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

You can add a delegate in the Client-side SDK using the following code:

System.Action<SettingsEnvironment> environmentChangedDelegate = (SettingsEnvironment changedTo) =>
{
Debug.Log("Environment changed to " + changedTo.ToString());
};

AccelBytePlugin.environmentChanged += environmentChangedDelegate;

You can add a delegate in the Server-side SDK using the following code:

System.Action<SettingsEnvironment> environmentChangedDelegate = (SettingsEnvironment changedTo) =>
{
Debug.Log("Environment changed to " + changedTo.ToString());
};

AccelBytePlugin.environmentChanged += environmentChangedDelegate;System.Action<SettingsEnvironment> environmentChangedDelegate = (SettingsEnvironment changedTo) =>
{
Debug.Log("Environment changed to " + changedTo.ToString());
};

AccelBytePlugin.environmentChanged += environmentChangedDelegate;

You can retrieve the active environment information in the Client-side SDK using the following code:

SettingsEnvironment activeServerEnvironment = AccelByteServerPlugin.GetEnvironment();

You can retrieve the active environment information in the Server-side SDK using the following code:

SettingsEnvironment activeServerEnvironment = AccelByteServerPlugin.GetEnvironment();
NOTE

We recommend changing the environment before any users have logged in in order to avoid undefined behavior or other code issues.