Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved How to set environment through script

Discussion in 'Cloud Save' started by hyunwookimbob, Apr 5, 2023.

  1. hyunwookimbob

    hyunwookimbob

    Joined:
    Mar 10, 2023
    Posts:
    8
    Is there a way to set a Cloud Save environment through code? I currently have a 'production' and 'development' environment and whenever I cloud save, it automatically saves the player data on the 'production' environment.

    Remote Config has
    SetEnvironmentID
    function so, I was wondering if Cloud Save has something like that.
     
  2. MileyUnity

    MileyUnity

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    92
    Here's a quick snippet that will do that for you :), I usually do this specifically for debug and editor builds so that the production game automatically uses the right environments and I won't forget to change that when making a final build.

    Code (CSharp):
    1.            
    2. InitializationOptions options = new();
    3.  
    4. if (Debug.isDebugBuild || Application.isEditor)
    5. {
    6.     options.SetEnvironmentName("dev"); // sets the environment for all other UGS services
    7.     RemoteConfigService.Instance.SetEnvironmentID("environment-id-goes-here"); // Remote Config has its own override system
    8. }
    9.  
    10. await UnityServices.InitializeAsync(options);
    11.  
     
    hyunwookimbob likes this.
  3. hyunwookimbob

    hyunwookimbob

    Joined:
    Mar 10, 2023
    Posts:
    8
    Thank you!!!