Search Unity

Migrated from RemoteSettings to RemoteConfig -> Questions & Issues

Discussion in 'Unity Remote Config' started by PeachyPixels, Mar 26, 2020.

  1. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Hi there,

    I've just migrated from RemoteSettings to RemoteConfig and have stumbled across (what I believe are) a few issues along the way.

    1) I setup the config data using the web dashboard, but initially struggled trying to create an environment called Development. It wasn't until I created a dummy one then installed the package in the game, that the built-in Development & Release environments were auto-created (and subsequently appeared in the dashboard)

    2) The RemoteConfig docs below reference RemoteConfigSettings but if I'm not mistaken that's part of the old RemoteSettings API that requires Unity Analytics. Hopefully just a docs typo?

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

    3) The docs states that games running in the editor will always use the Development environment. But for me it's always honouring the default environment in the editor (in this case Release). If I switch the default environment, this is then used next time the game runs (in the editor)

    4) I was expecting the FetchCompleted event to fire in the following order Defaults -> Cache -> Remote but all I ever see reported is Remote. Even if I disable the network connection, it still reports Remote but with a Failed status. Is this intended behaviour?

    5) I setup configs for each environment (called Default Config) but this doesn't show up in the editor UI. All I see is Settings Config

    6) Is there a way to change config names?

    7) I assume that no rules is ok and in-effect means all players?

    Using 1.2.0 (preview 4) the fetch code is like so...

    Code (CSharp):
    1. ConfigManager.FetchConfigs(null, null);
    And settings are retrieved like so...

    Code (CSharp):
    1. ConfigManager.appConfig.GetBool(<name>, <default>)
    Any help would be greatly appreciated. Many thanks!
     
  2. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Regarding points 1&3...

    I just saw this in the 1.2.0.preview4 online docs...

    Deleting the environment named Development is possible however; using a Development Build version of your Unity Project may cause unintended or breaking behavior. Those builds will receive the settings and rules from the environment which is set as the default environment.

    So the web dashboard allowed me to corrupt the data to the point where behaviour is now broken, which is not ideal. Is there a way to undo this please?
     
    Last edited: Mar 26, 2020
  3. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Regarding point 4 (only the FetchCompleted -> Origin.Remote event is fired)...

    I looked at the ConfigManager code and the reason for this is that initialisation happens before scene load...

    Code (CSharp):
    1. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    2. private static void Initialize()
    3. {
    4.   Init();
    5. }
    But my game initialisation happens immediately after (splash) scene load.

    Would it be possible to allow for manual RemoteConfig initialisation please?
     
  4. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @PInvoke sorry you're running into issues, hopefully I can help with them!
    1) Yeah, this is a weird finicky behavior between the <1.0.X packages and the >1.1 packages. In the past, there were Development and Release environment names so those are reserved, and can only be made by the package.

    2) Yeah, the 1.0.9 and below packages used the analytics runtime to get configs, but didn't require analytics to be enabled. In 1.1.0 and beyond (1.2.0-preview.4 is currently undergoing verification), we've fully decoupled from the analytics runtime in the engine, and no longer rely on that.

    3) Did this happen in a 1.0.X package? If so, that's definitely a bug on our end and we'll get it addressed. In 1.1.0 and beyond, the default environment is served, unless you call ConfigManager.SetEnvironmentID with the id of the environment you'd like to use before calling FetchConfigs

    4) Yeah, this was a big issue in 1.0.X, since we leveraged the old analytics runtime, which can capture the default remote config call. Do you notice this behavior in 1.2.0-preview.4?

    5) Sorry, that seems to be a naming inconsistency, we'll fix that. The default config is the settings config.

    6) We don't offer that today, but we're exploring it when we look at adding multiple configs.

    7) Yep! No rules means all users.

    As for 1&3 and the docs, that seems to be an error in the docs, we'll get that addressed, the development build shouldn't cause any issues. Let me know if you see any
     
  5. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    This is an interesting feature request, the initialization method initializes the Remote Config underlying classes and begins the process of loading from the cache. Would you like that to be invoked by you manually?
     
  6. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    I think that would be a worthwhile addition :)

    Analytics already does this and I'm certainly using it to good effect...

    Code (CSharp):
    1. Analytics.initializeOnStartup = false;
    Code (CSharp):
    1. AnalyticsResult result = Analytics.ResumeInitialization();
    I have a GlobalManager (DoNotDestroyOnLoad) object whose Init (Coroutine) is invoked on Start of the splash screen. Allowing manual initialisation means this can be delayed a little, at which point objects will exist and event handlers assigned (so at the very least, should mean a FetchCompleted for Cache & Remote)
     
    rambod likes this.
  7. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Hi rambod,

    Thanks for the reply.

    Sorry can't say, I initially used 1.0.9 but moved to 1.2.0 (preview4) fairly quickly. This issue is outlined in your docs now, but I wondered if there was a way to fix the backend data?

    As of right now, I'm going to have to manually code the SetEnvironmentId to handle this. Not a big deal, but would be nice to not have to-do this if it's just corrupt data that can be fixed.
     
  8. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    Thank you! I've added to our list of features to add.
    One thing that might be helpful for this in the meantime, is that ConfigManager.appConfig will have your cached config loaded by the time your GlobalManager loads up. You can check the origin field on the RuntimeConfig object as well for if needed.
     
    PeachyPixels likes this.
  9. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    For this one, I need some more details to better understand what's going on. What's the data you're worried about being corrupted?

    For some background on the custom environment work: our hope with it is that you can do things like using a precompile directive for a development build to set the environment id for your test environment, then have your production build use the default environment.
     
    vd_unity likes this.
  10. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Great idea. Thanks!

    All the calls to RemoteConfig from within the game are made from an abstract class, so as a work around just before calling FetchConfigs I call my UpdateSettings method manually. This will force whatever settings have currently been fetched into the settings POCO.

    Code (CSharp):
    1. UpdateSettings(MapSource(ConfigManager.appConfig.origin));
    However, on running I was surprised to see the source was Defaults although the values appeared to be from the cache. Did a little digging and think I found why. In ConfigManager.Init you will see the following code...

    Code (CSharp):
    1. LoadFromCache();
    2. RawResponseReturned += OnRawResponseReturned;
    3. RawResponseValidated += SaveCache;
    But the LoadFromCache method appears to need the event handlers to update certain values, so I believe they should be like so...

    Code (CSharp):
    1. RawResponseReturned += OnRawResponseReturned;
    2. RawResponseValidated += SaveCache;
    3. LoadFromCache();
    I changed them around and am now seeing the expected result (that is, Cache then Remote) but didn't dig deeper to truly understand the code. Will leave that one to you :)

    I noticed there is no event fired for Default on Init, so would be nice if that could be added. Saying that, to be honest my UpdateSettings method just issues calls to the Get<Type> methods with defaults. Meaning the game just takes what it can when it can and doesn't really care where they came from or whether the fetch was a success or not. The defaults are sensible and the values validated (post fetch) to try and detect cache tampering.

    Hope that helps!
     
    Last edited: Mar 28, 2020
    rambod likes this.
  11. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    In the mess of setting up the initial Development environment (i.e. conflicting with the in-built one) the data appears to now be in that state where the auto-environment feature isn't working.

    Regardless of whether the Development Build flag is checked (or not) the values for the default environment are always used. Basically it means I now have to code around this. Not ideal, but not a deal breaker either. I just liked the idea of the auto-environment feature.
     
  12. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Another thing I noticed is that ConfigManager.Init is still referencing Unity Analytics...

    Code (CSharp):
    1. userid = AnalyticsSessionInfo.userId
    Not sure if the intention was to completely decouple from it, but thought I'd mention.
     
  13. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @PInvoke

    Thanks for catching the bug with the events not being properly applied (and showing us the fix - makes my job a lot easier :p)! We're going through verification for the fix now and should have a new versions of the 1.2.X, and 1.3.X package releases out by the end of the week.

    As for this one, if you're using package versions 1.1.0+ this is expected behavior, the default environment will be served to the runtime unless you call ConfigManager.SetEnvironmentID. However, I'll flag this with the team to look into if we can provide the auto-environment feature, while also allowing you to create more than two environments.

    Lastly, regarding the last UnityAnalytics dependency, that piece of code doesn't actually require the analytics package, or analytics to be turned on. That being said, we are looking for a fallback that doesn't require the analytics namespace, but we want to be careful, in case developers are relying on the fallback user ID for reporting.
     
    PeachyPixels likes this.
  14. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @PInvoke we just released 1.2.0-preview.5 last night, with the fix you noted about the ordering of the initialization, let us know if you see the problem again! It'll also be included in the next 1.3 release as well
     
    PeachyPixels likes this.
  15. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Thanks rambod :)

    Beat you to it, saw earlier and installed and a-ok! Thanks for the speedy work with this, much appreciated. Sorry for not replying earlier, been fighting Cloud Build today unfortunately.

    I'm a few weeks away from my 1.0 release and although 1.2-preview seems stable to me, I would be interested to hear your thoughts on a Unity preview package going live? I'm reluctant to revert to 1.0.9 as 1.2 seems a nice step forward.

    Will 1.2 go live before 1.3 or will you just skip it and push 1.3 live eventually?
     
    Last edited: Apr 2, 2020
    rambod likes this.
  16. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    You're welcome. Am a life long developer (but newbie game designer) so old habits and all that :)

    Ironically, I added Environment support to my abstract class yesterday and prefer the manual control now. Sorry! :rolleyes:

    That said, I definitely think this would be of use to most people as the vast majority will only ever require Develpoment & Release environments and having them controlled automatically does ultimately mean less work.
     
  17. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    I'm glad things are working as expected!

    We are currently going through the process of getting 1.2.0-preview.5 as a verified package, so we can confidently say that version is production ready already!

    We will eventually get 1.3 verified as well, but that probably won't be for another few months, since we want to make sure it's been in the wild a bit and there are no issues, since the addition of JSON as a type is a substantial change.


    No need to be sorry! I'm glad you're finding better than the previous system :D
     
    PeachyPixels and vd_unity like this.
  18. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    That's great, thanks!

    Btw am still only seeing the one event back from RemoteConfig (i.e. Remote) so am assuming the Cached event change\fix is further down the line? Either way, the spoof Cached event I added is a good workaround for now.
     
  19. swats1010

    swats1010

    Joined:
    Jun 26, 2019
    Posts:
    11
    Hi, @rambod I was trying to use the RemoteConfig in my game .
    I imported the package from the asset store and while using it I am getting this error .

    ````
    The type or namespace name 'RemoteConfig' does not exist in the namespace 'Unity' (are you missing an assembly reference?)
    ````
    Dont understand what could i possibly do to solve it .Please help !
     
  20. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    Hi rambod!

    Just thought I'd check up on this as I'm approaching launch and keen to drop the use of a preview package before.

    I noticed that there is no 1.2.0 release yet, but there is a 1.2.1 preview (with no code changes it seems)

    Just wondering what your latest advice would be on this. Shall I stick with 1.2.0-p5 or switch to 1.2.1-p or wait for the official release?
     
    Last edited: May 6, 2020
  21. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    HI. Today started to migrate from Remote Settings and stumbled on this issue:
    Any float key retrives "0" value after I pull it. However in web dashboard it shows correct value.
    What am i missing?
     
  22. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show the code that you are using and screenshots of your Dashboard and Editor settings. Is this in the Release or Development environment? Is it only for float values? I just tried with the latest release, and was able to push a float value of .01
     
    Last edited: May 11, 2020
  23. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    713
    No worries, I can see 1.2.1 has been released to production. Updated and all seems a-ok!
     
    rambod likes this.
  24. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    Sorry, for now i deleted remote settings. Will back to it in next app update. I tried all enviroments: release, development and my custom. Tried float and strings. Strings work ok, when I press pull in editor window I get correct value. Floats always become 0 after pulling it. And no matter where did I create it in unity or web(

    Also tried to get it with code, in editor and real device, no luck.
     
  25. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Do you mean Remote Config and not Remote Settings? Please use the latest version of Remote Config, I just successfully tested with float values. We have many users successfully using Remote Config, so it's something in your configuration. If you continue to have issues, please provide screenshots of your RC dialog in the Editor, and your RC dashboard.
     
  26. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    Hi guys, please help me check ApplyRemoteSettings(ConfigResponse configResponse)
    it always return configResponse Fail with this error
    Newtonsoft.Json.Linq.JObject.System.Collections.Generic.IDictionary<System.String,Newtonsoft.Json.Linq.JToken>.get_Values () [0x00000] in <bc3985d37b0241b48fc21474b2de25bd>:0

    Current version: 2.0.1
    Thanks!
     
  27. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Was this working previously? Please share your full RC script.
     
  28. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    no, it hasn't worked yet!
    void Awake()
    {
    // Add a listener to apply settings when successfully retrieved:
    ConfigManager.FetchCompleted += ApplyRemoteSettings;
    ConfigManager.SetEnvironmentID("XXXX-XXXX-XXXX-XXXX-XXXX");
    ConfigManager.FetchConfigs(new userAttributes(), new appAttributes());
    }

    void ApplyRemoteSettings(ConfigResponse configResponse)
    {
    switch (configResponse.requestOrigin) {
    case ConfigOrigin.Default:
    Debug.Log ("[RemoteSetting] No settings loaded this session; using default values.");
    break;
    case ConfigOrigin.Cached:
    Debug.Log ("[RemoteSetting] No settings loaded this session; using cached values from a previous session.");
    break;
    case ConfigOrigin.Remote:
    Debug.Log ("[RemoteSetting] New settings loaded this session; update values accordingly.");
    SyncData();
    assignmentId = ConfigManager.appConfig.assignmentID;
    break;
    }
    }
     
  29. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I don't believe that is the full code. Please compare to the code listed here https://docs.unity3d.com/Packages/com.unity.remote-config@2.0/manual/CodeIntegration.html
     
  30. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    I almost copy from CodeIntegration link.
    it always return ConfigOrigin.Remote and Fail
    ConfigManager.appConfig has enviroment null with Newtonsoft.Json error
     
  31. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you don't want to "almost" copy it, you'll need all of the code. Please show your full code.
     
  32. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.RemoteConfig;
    4. using UnityEngine;
    5.  
    6. public class RemoteSetting : MonoBehaviour
    7. {
    8.     public struct userAttributes
    9.     {
    10.         public bool expansionFlag;
    11.     }
    12.  
    13.     public struct appAttributes
    14.     {
    15.         public int level;
    16.         public int score;
    17.         public string appVersion;
    18.     }
    19.  
    20.     public string assignmentId;
    21.  
    22.     void Awake()
    23.     {
    24.         // Add a listener to apply settings when successfully retrieved:
    25.         ConfigManager.FetchCompleted += ApplyRemoteSettings;
    26.         ConfigManager.SetEnvironmentID("XXXXXXX");
    27.  
    28.         // Fetch configuration setting from the remote service:
    29.         ConfigManager.FetchConfigs(new userAttributes(), new appAttributes());
    30.     }
    31.  
    32.     void ApplyRemoteSettings(ConfigResponse configResponse)
    33.     {
    34.         switch (configResponse.requestOrigin) {
    35.             case ConfigOrigin.Default:
    36.                 Debug.Log ("[RemoteSetting] No settings loaded this session; using default values.");
    37.                 break;
    38.             case ConfigOrigin.Cached:
    39.                 Debug.Log ("[RemoteSetting] No settings loaded this session; using cached values from a previous session.");
    40.                 break;
    41.             case ConfigOrigin.Remote:
    42.                 Debug.Log ("[RemoteSetting] New settings loaded this session; update values accordingly.");
    43.                 SyncData();
    44.                 assignmentId = ConfigManager.appConfig.assignmentID;
    45.                 break;
    46.         }
    47.     }
    48.  
    49.     [Header("Remote Sync Data")]
    50.     public int missionStars;
    51.  
    52.     void SyncData()
    53.     {
    54.         missionStars = ConfigManager.appConfig.GetInt("mission_stars");
    55.     }
    56. }
    yep it's all my code!
     
  33. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Finally after a day. Are you using Newtson.JSON elsewhere in your project? Can you try a new project with only RC to compare, if so? And please share a screenshot of your error.
     
  34. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    yep, I created new empty project to test RC, but it's still not working!

    upload_2021-6-26_12-35-35.png
    upload_2021-6-26_12-36-2.png
     
  35. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I don't follow. A new project would not have other JSON libraries. Ensure to be using the latest RC package in Package Manager with no other components in the project, as a test. What version of RC and Unity are you using?
     
  36. naruto93

    naruto93

    Joined:
    May 6, 2015
    Posts:
    17
    I'm using Current version: 2.0.1
     
  37. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    And you created a new project without any other libraries? If so, please remove the /Library folder, zip it up, and attach it here.