Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Default config value without internet connection

Discussion in 'Unity Remote Config' started by Pavel_Belokruenko, Mar 1, 2020.

  1. Pavel_Belokruenko

    Pavel_Belokruenko

    Joined:
    Sep 14, 2018
    Posts:
    15
    Can I set default config in case of first game run without internet connection?

    I think the most easy way to solve this situation is load config from resources and manually set it, or give possibility to set default config from editor but there is no functional to do this (or i couldn't find it).
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    vd_unity likes this.
  3. Pavel_Belokruenko

    Pavel_Belokruenko

    Joined:
    Sep 14, 2018
    Posts:
    15
    So if my config contains (for example) more then 1000 values and there is no internet connection - I need to set manually each field with default value in code? And for each default value change i need to manage this values?

    Even if I already have all default values predefined in my editor config?

    It sounds like hell.

    All Apple Arcade games should have an opportunity to be ran without internet connection, so for Arcade games this config is useless?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you show a screenshot of where you are currently setting your default values, so there is no confusion?
     
  5. Pavel_Belokruenko

    Pavel_Belokruenko

    Joined:
    Sep 14, 2018
    Posts:
    15
    For now I'm using my own config file downloaded from sftp, but I'm interested to upgrade to Remote Config package.

    I'll try to explain more detailed: when user first runs an application without internet connection - config with default values (zeroes and empty strings) will be generated without any rules and key value pairs in it.

    And now I'm as developer who wants to make his partially offline game should make a couple of things to make this work:
    1) download remote config in editor and get scriptable object with already preset values, put it in my resources folder.
    2) write my own parser for this config (keyValuePairs, rules) to copy values from my resources pre-downloaded config to default generated config
    3) safely start the game

    Method you have offered may help me to write my own parser, but in my opinion this is basic functionality that should already be included in this package.
     
    Last edited: Mar 3, 2020
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Thank you for your suggestion. You could essentially do the same with a single INCLUDE file for your default values, and edit them in one place. Default values would not be expected to change often, and typically include values other than 0's and 1's. I am also checking with the team here.
     
  7. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    I have the same problem. I created a config and wrote the default values there, which I plan to change remotely. Then I built an app that included this config with default values. I expect that if there is no Internet, I will get my default value, but I get "0"
    Code (CSharp):
    1. levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance");
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Make sure to use the latest release of Remote Config. Please share the code that you are using.
     
  9. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    I'am using version 1.2.2.
    upload_2020-5-27_21-32-4.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.RemoteConfig;
    4. using UnityEngine;
    5.  
    6.     public class RemoteConfig : MonoBehaviour
    7.     {
    8.         public static float levelBalance = 0.1f; // 0.1 value for test
    9.  
    10.         public struct UserAttributes
    11.         {
    12.             // Optionally declare variables for any custom user attributes:
    13.             public int level;
    14.         }
    15.  
    16.         public struct AppAttributes
    17.         {
    18.             // Optionally declare variables for any custom app attributes:
    19.             public string appVersion;
    20.         }
    21.  
    22.         // Retrieve and apply the current key-value pairs from the service on Awake:
    23.         void Awake()
    24.         {
    25.             // Add a listener to apply settings when successfully retrieved:
    26.             ConfigManager.FetchCompleted += ApplyRemoteSettings;
    27.  
    28.             // Set the user’s unique ID:
    29.             //ConfigManager.SetCustomUserID("some-user-id");
    30.  
    31.             // Set the environment ID:
    32.             ConfigManager.SetEnvironmentID("91dae037-7973-4643-b9c4-f3f15b972f2e");
    33.  
    34.             // get default value
    35.             levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance"); // expect 3.17, but get 0
    36.         }
    37.  
    38.     void Start()
    39.     {
    40.             FetchConfig();
    41.         }
    42.  
    43.         private void FetchConfig()
    44.         {
    45.             var userAttributes = new UserAttributes();
    46.             var appAttributes = new AppAttributes();
    47.             userAttributes.level = MM.Inventory.GetInt(MM.Inventory.LEVEL_ID);
    48.             appAttributes.appVersion = Application.version;
    49.  
    50.             // Fetch configuration setting from the remote service:
    51.             ConfigManager.FetchConfigs<UserAttributes, AppAttributes>(userAttributes, appAttributes);
    52.         }
    53.         void ApplyRemoteSettings(ConfigResponse configResponse)
    54.         {
    55.             // Conditionally update settings, depending on the response's origin:
    56.             switch (configResponse.requestOrigin)
    57.             {
    58.                 case ConfigOrigin.Default:
    59.                     Debug.Log($"RemoteConfig: No settings loaded this session; using default values.");
    60.                     break;
    61.                 case ConfigOrigin.Cached:
    62.                     Debug.Log($"RemoteConfig: No settings loaded this session; using cached values from a previous session.");
    63.                     break;
    64.                 case ConfigOrigin.Remote:
    65.                     Debug.Log($"RemoteConfig: New settings loaded this session; update values accordingly.");
    66.                     levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance"); // I get 0 again
    67.                     break;
    68.             }
    69.         }
    70.     }
    71. }
    if the Internet is available I get 3.17. And after the first Internet connection I get 3.17 without Internet.

    UPD: I get: configResponse.status == ConfigRequestStatus.Failed and configResponse.requestOrigin == ConfigOrigin.Remote.
    But I expect: configResponse.status == ConfigRequestStatus.Success and configResponse.requestOrigin == ConfigOrigin.Default
     
    Last edited: May 27, 2020
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please try moving this line from Awake to the last line in FetchConfig, Awake is fired before Start and you haven't yet initialized RC and a null is likely treated as 0.

    levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance"); // expect 3.17, but get 0
     
  11. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    Thank you, this is really my mistake, but it didn't help. I still get 0 and ConfigRequestStatus.Failed. Also file RemoteConfig.json in my persistentDataPath folder (MacOS) is not created without the Internet connection.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please try this syntax:

    float myDefault = 0.1f;
    levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance" , myDefault);
     
  13. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    Now I got 0.1
     
    JeffDUnity3D likes this.
  14. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    And then what?:) I still expect to get the value from the local config (3.17), not duplicate it in the code. Is this a confirmed bug or a problem only on my project?
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can set the default value to anything you want. The second parameter is the default value if there is no Internet connection. If you have connected at least once in the past, it will use the last retrieved (and cached) value. If the user has never connected and this is their first request and there is no Internet, it will use the default value.
     
    brn_ghs likes this.