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.

Question How to set remote config default values?

Discussion in 'Unity Remote Config' started by Clicksurfer, Jan 3, 2021.

  1. Clicksurfer

    Clicksurfer

    Joined:
    Aug 17, 2014
    Posts:
    76
    I am using remote config and most of the time the game works as intended. However, in some rare cases it seems the value of all integers I'm supposed to get from remote config is 0, and this breaks my game.

    I assume this is happening because the application is failing to fetch remote config from online/cache in these edge cases, and thereby using defaults. However, in this case, where is the default stored? Where can I override it with other values?

    Thanks in advance!
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Like this:

    int myDefaultValue = 1;

    enemyHealth = ConfigManager.appConfig.GetInt ("enemyHealth", myDefaultValue);
     
    ltomov and Clicksurfer like this.
  3. Clicksurfer

    Clicksurfer

    Joined:
    Aug 17, 2014
    Posts:
    76

    Really? That's really strange! That's the method I've been using all this time.

    In my starting scene I have this script that initializes remote config via ConfigManager, using an empty struct for userAttributes and appAttributes.
    This script is essentially a Singleton and has methods which can be called by other scripts to get remote config values.

    In this script, for instance, the following method exists:
    Code (CSharp):
    1.     public int GetInt(string key, int default_value)
    2.     {
    3.         try
    4.         {
    5.             Debug.Log("BBB - Returning value from remote config for key: " + key);
    6.             return ConfigManager.appConfig.GetInt(key);
    7.         }
    8.         catch
    9.         {
    10.             Debug.Log("BBB - Returning default value for key: " + key);
    11.             return default_value;
    12.         }
    13.     }
    Then, for example. I can get int values from remote config by calling GetInt:

    Code (CSharp):
    1.         Debug.Log("BBB - twoStarScore before getting remote config: " + TwoStarsScore);
    2.         if (RemoteConfigManager.ConfigLoaded())
    3.         {
    4.             ThreeStarsScore = RemoteConfigManager.RemoteConfig.GetInt(GenericUIScript.GetSceneName() + "_ThreeStarsScore", ThreeStarsScore);
    5.             TwoStarsScore = RemoteConfigManager.RemoteConfig.GetInt(GenericUIScript.GetSceneName() + "_TwoStarsScore", TwoStarsScore);
    6.             FillMultiplier = RemoteConfigManager.RemoteConfig.GetFloat(GenericUIScript.GetSceneName() + "_FillMultiplier", FillMultiplier);
    7.         }
    8.         Debug.Log("BBB - twoStarScore after getting remote config: " + TwoStarsScore);
    For this example it's important to note all these params have values above 0 in remote config, in both Release and Development environment:

    upload_2021-1-7_10-7-12.png

    And yet during runtime, I see that the game gets 0 for all these values from remote config.
    Any idea what may be causing this?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are not setting the default value. This is your code:

    ConfigManager.appConfig.GetInt(key);

    and the code I suggested

    enemyHealth = ConfigManager.appConfig.GetInt ("enemyHealth", myDefaultValue);

    Note the second value is the default value.

    You also use this syntax:

    FillMultiplier = RemoteConfigManager.RemoteConfig.GetFloat(GenericUIScript.GetSceneName() + "_FillMultiplier", FillMultiplier);

    I would not recommend using your default value also as the assignment value (FillMultiplier). If you choose this approach, be sure to set FillMultiplier with your default value first. Did you write the GetInt method above in your own class?

    Before attempting to customize the code, I would recommend to get the basics working first and build on success instead of chasing bugs. Please use the recommended code here:

    https://docs.unity3d.com/Packages/com.unity.remote-config@2.0/manual/CodeIntegration.html
     
  5. Clicksurfer

    Clicksurfer

    Joined:
    Aug 17, 2014
    Posts:
    76
    Thanks for the help Jeff, after implementing the code as you suggested, it worked just fine :)

    I have to note, though - the reason I did not use default values correctly in the first place is because there is no explicit example in the documentation on how to set default values when getting values from ConfigManager. It might be a good idea to add a little section explaining that.
     
    JeffDUnity3D likes this.