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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Offline but ConfigOrigin set to Remote

Discussion in 'Unity Remote Config' started by petera1980, Sep 20, 2020.

Thread Status:
Not open for further replies.
  1. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Hello,

    I use Unity 2019.4.9f1

    I always get ConfigOrigin.Remote when I run in offline. I tried on mobile - the same.
    I tried [1.2.3] and [1.2.4-preview.4].

    Switch statements worked correctly with v1.09 for me.

    Code (CSharp):
    1. private void ApplyRemoteSettings(ConfigResponse cr)
    2.     {
    3.         switch (cr.requestOrigin)
    4.         {
    5.             case ConfigOrigin.Default:
    6.                 Debug.Log("No settings loaded this session; using default values.");
    7.                 break;
    8.             case ConfigOrigin.Cached:
    9.                 Debug.Log("No settings loaded this session; using cached values from a previous session.");
    10.                 break;
    11.            [B] case ConfigOrigin.Remote: [/B]
    12.                 Debug.Log("New settings loaded this session; update values accordingly.");
    13.                
    14.                 break;
    15.         }
    16.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you actually try to load specific values? Your case statements are empty, can you retrieve values at that point and confirm that remote values or cached values are used? Provide the output of your Debug.Log statements and the server-side values and the last cached expected value.
     
  4. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Yes, in online mode all values are retried and cached. Also all values that I change in web site are also changed in the next reload of game.
    But, if I delete the cache file (json) manually, simulating the android clean app cache option and close internet connection on mobile, then value that I get is 0 as default static variable assignment in cs. (if I had set it to 0.5f then I will got 0.5f)

    The problem is that even in offline mode and with existing cached json file the requestOrigin return ConfigOrigin.Remote instead of ConfigOrigin.Default BUT whatever read from json cached file and return json's cached values.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide specific steps to reproduce, sorry I'm not quite following. Please provide your Debug.Log output and the corresponding code so I can try to reproduce here, as requested. It sounds like what you are saying that it's properly reading the local cache after a previous successful connection, but it's triggering/returning the wrong requestOrigin (Remote vs Cached). You are also deleting files. Can you elaborate on the "android clean app cache option"?
     
  6. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Hello,
    Remote Config 1.2.3 or 1.4.0 preview 1 (get the same result)
    Unity 2019.4.9f1

    This is code in awake :

    Code (CSharp):
    1.  void Awake()
    2.     {
    3.        ConfigManager.FetchCompleted += ApplyRemoteSettings;
    4.         ConfigManager.FetchConfigs<userAttributes,        appAttributes>(new userAttributes(), new appAttributes());
    5. }
    Then

    Code (CSharp):
    1.  private void ApplyRemoteSettings(ConfigResponse cr)
    2.     {
    3.        [B] print(cr.requestOrigin);[/B]
    4.         switch (cr.requestOrigin)
    5.         {
    6.        
    7.             case ConfigOrigin.Default:
    8.                 Debug.Log("No settings loaded this session; using default values.");
    9.                 break;
    10.             case ConfigOrigin.Cached:
    11.                 Debug.Log("No settings loaded this session; using cached values from a previous session.");
    12.                 break;
    13.             case ConfigOrigin.Remote:
    14.                 Debug.Log("New settings loaded this session; update values accordingly.");
    15.                 RemoteConfigValues.VirtualCamera.DeadZoneWidth = ConfigManager.appConfig.GetFloat("DeadZoneWidth");
    16.                 RemoteConfigValues.VirtualCamera.DeadZoneHeight = ConfigManager.appConfig.GetFloat("DeadZoneHeight");
    17.                 break;
    18.         }
    19.     }
    Then I disable Ethernet in PC imitating offline. I get the following code :

     
    Last edited: Sep 27, 2020
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  8. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    I added SetEnvironmentID but the the problem still exists.

    In offline it still shown cr.requestOrigin == ConfigOrigin.Remote

    It is weird that the R.C does not understand whether it is online or offline because it is not set SetEnvironmentID.

    Code (CSharp):
    1.  
    2.  void Awake()
    3.     {
    4. ConfigManager.SetEnvironmentID("fa1398cc-4780-4913-a982-e06b05245b7d");
    5. ConfigManager.FetchCompleted += ApplyRemoteSettings;
    6. ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
    7. }
    8.  
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I suspect if you are deleting the cache between sessions or similar, it would show as Remote. What would your expectation be? It's not Default because it expects Cached, it's not Cached because you deleted it.
     
  10. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    1) With deleted cache file it shows Remote in offline mode.
    2)Why it is expects cache if cache file do not exists ? Maybe some checks in code will fix this bug.
    3)With cache file and offline mode it still shown Remote instead of Cached, but bring values from cached file.
    If I manually change values in RemoteConfig.json I will see new values in Console but in ConfigOrigin.Remote case statement not in ConfigOrigin.Cached.

    I tried to move initialization code from Awake to Start but the same.

    It is not big problem, this case it is rare to occur.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    It would not be a bug if you've deleted a resource, but a feature request. It should not say Cached if Cached is not available. Again, what is your expectation if the user does this? What switch statement would you like to add, since your use-case doesn't seem to fit into the current ones. If it is expecting Cached but someone deleted the cache, would you expect it to go back to Default, or a new value.
     
  12. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    I expect to go to Default in this case.
    If cache file do not exists and no internet connection exists this meas that I have to provide default values to user.
    But I get 0 in all variables in this case because no cache exists and it is offline and system still return Remote...

    Why Default then exists in switch if never used ?

    As I mentioned before only version 1.0.9 falls into Default. All other versions return Remote.
     
  13. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I don't follow. Default is used if there is no Internet connection and there hasn't been a previous session. That's not the case here. You've deleted files. Returning Default in this case would be difficult to support for you. Users would call into you complaining they lost progress or similar. You wouldn't know if they are first time users or just deleted their cache somehow, you haven't specified the process.
     
  14. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Ok I got it. I did not understand algorithm of RC well.

    Thank you for explanation.
     
    JeffDUnity3D likes this.
  15. monu98

    monu98

    Joined:
    Sep 7, 2020
    Posts:
    5
    @JeffDUnity3D Do we have to write some code in ConfigOrigin.Cached or it will automatically fetch from a cached file?

    Thank you
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Automatically, give it a test!
     
  17. pixelminer

    pixelminer

    Joined:
    Jul 24, 2011
    Posts:
    22
    Just in case someone else ends up here, don't waste your time with ConfigOrigin. ConfigOrigin is always ConfigOrigin.Remote because ConfigOrigin.Default and ConfigOrigin.Cached are never used in the actual Remote Config package's code. Sure they're are in the example code from who knows what version but if you actually search the code in com.unity.remote-config@2.1.2, & com.unity.remote-config-runtime@2.1.2, I'm on version 2.1.2 obviously, you will NOT find a single occurrence of ConfigOrigin.Default or ConfigOrigin.Cached in the actual code for the package. You will however find that configResponse orgin is set to ConfigOrigin.Remote on line 368 of ConfigManagerImpl.cs and then passed straight into the configResponse as is in line 124 of the same file. Someone at Unity seriously needs to update the documentation so people don't waste hours of their lives figuring this out like I just did.
     
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are referring to an older version of Remote Config, the latest is 3.0.0-pre.9 . And if your claims are true, we wouldn't update the documentation, we would fix the code!
     
  19. pixelminer

    pixelminer

    Joined:
    Jul 24, 2011
    Posts:
    22
    Actually, it might be better to get rid of ConfigOrigin completely. I found that since the class which uses the Remote Config data should validate and save a copy of the data it gets from Remote Config anyway, whether the data is from online or cache made no difference in the end. The code I have working now does not use ConfigOrigin and works just fine, better even, since my code has to take responsibility for keeping track of data it itself uses when it's available. Appreciate the features but I think in this case simplicity would be better.
     
  20. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Many developers are already using ConfigOrigin so removing it would break their code. In your case it sounds like you don't need the feature so you can safely ignore it. I will go ahead and lock this thread now.
     
Thread Status:
Not open for further replies.