How to set remote config default values?

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!

Like this:

int myDefaultValue = 1;

enemyHealth = ConfigManager.appConfig.GetInt (“enemyHealth”, myDefaultValue);

2 Likes

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:

    public int GetInt(string key, int default_value)
    {
        try
        {
            Debug.Log("BBB - Returning value from remote config for key: " + key);
            return ConfigManager.appConfig.GetInt(key);
        }
        catch
        {
            Debug.Log("BBB - Returning default value for key: " + key);
            return default_value;
        }
    }

Then, for example. I can get int values from remote config by calling GetInt:

        Debug.Log("BBB - twoStarScore before getting remote config: " + TwoStarsScore);
        if (RemoteConfigManager.ConfigLoaded())
        {
            ThreeStarsScore = RemoteConfigManager.RemoteConfig.GetInt(GenericUIScript.GetSceneName() + "_ThreeStarsScore", ThreeStarsScore);
            TwoStarsScore = RemoteConfigManager.RemoteConfig.GetInt(GenericUIScript.GetSceneName() + "_TwoStarsScore", TwoStarsScore);
            FillMultiplier = RemoteConfigManager.RemoteConfig.GetFloat(GenericUIScript.GetSceneName() + "_FillMultiplier", FillMultiplier);
        }
        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:

6697675--768553--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?

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

Thanks for the help Jeff, after implementing the code as you suggested, it worked just fine :slight_smile:

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.

1 Like

Use RemoteConfigService instead of ConfigManager

RemoteConfigService.Instance.appConfig.GetInt(“enemyHealth”);