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

Question Problem Changing Environment

Discussion in 'Unity Remote Config' started by Sebasapk, May 19, 2021.

  1. Sebasapk

    Sebasapk

    Joined:
    Jun 4, 2020
    Posts:
    4
    I'm currently exploring Remote Config, but I found that I can´t change the environment.
    So, I have two environments and I wanted to use the second environment that is not by default. As you can see in the script I used "ConfigManager.SetEnvironmentID" to change the environment but It doesn't work.
    The ID of the environment to which I want to change is correct, I already verified it.
    Does anyone know why this is happening? and How can I solve it?
    Thanks.
    Code (CSharp):
    1.  public string EnvironmentID;
    2.     private struct userAttributes{}
    3.     private struct appAttributes {}
    4.  
    5.     private void Awake() {
    6.         ConfigManager.FetchConfigs<userAttributes,appAttributes>(new userAttributes(),
    7.         new appAttributes());
    8.         ConfigManager.FetchCompleted+=ApplyRemoteSettings;
    9.     }
    10.     private void Update() {
    11.         if(ConfigManager.appConfig.environmentID==EnvironmentID){
    12.             Debug.Log("Equal "+ConfigManager.appConfig.environmentID);
    13.         } else {
    14.             Debug.Log("Not Equal "+ConfigManager.appConfig.environmentID);
    15.         }
    16.     }
    17.     void ApplyRemoteSettings (ConfigResponse configResponse) {
    18.         // Conditionally update settings, depending on the response's origin:
    19.         switch (configResponse.requestOrigin) {
    20.             case ConfigOrigin.Default:
    21.                 Debug.Log ("No settings loaded this session; using default values.");
    22.                 break;
    23.             case ConfigOrigin.Cached:
    24.                 Debug.Log ("No settings loaded this session; using cached values from a previous session.");
    25.                 break;
    26.             case ConfigOrigin.Remote:
    27.                 Debug.Log ("New settings loaded this session; update values accordingly.");
    28.  
    29.                 ConfigManager.SetEnvironmentID(EnvironmentID);
    30.                 Debug.Log("Current Environment "+ConfigManager.appConfig.environmentID);
    31.                 break;
    32.         }
    33.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show the code where you are setting the environmentID. This may help https://docs.unity3d.com/Packages/com.unity.remote-config@2.1/manual/CodeIntegration.html
     
    Sebasapk likes this.
  3. Sebasapk

    Sebasapk

    Joined:
    Jun 4, 2020
    Posts:
    4
    The line where I change the environment is the 29 of the code I posted. About the variable "EnvironmentID", I assign its value from the inspector.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please review the documentation. You are setting the environmentID in the wrong location.
     
    Sebasapk likes this.
  5. Sebasapk

    Sebasapk

    Joined:
    Jun 4, 2020
    Posts:
    4
    Thanks, I didn´t realize about it. I put the line where I change the environment before "fetchconfigs".