Search Unity

FetchCompleted firing twice?

Discussion in 'Unity Remote Config' started by luvcraft, Nov 10, 2019.

  1. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    After learning about Remote Config at Dev Day LA today, I'm integrating it into my current project.

    After some initial confusion between Remote Config and the very-similar-but-deprecated Remote Settings, I've got it working, however when I run it the
    FetchCompleted
    callback is getting called twice; once with empty data before my
    ConfigManager.FetchConfigs
    call, and once with all the expected data as a result of that call.

    Where is that extra call coming from, and can I kill it so I don't get that empty data?
     
  2. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    Hey @luvcraft

    is the first call coming back with remote? If so, are you doing on Awake? My guess is that the first call is for the legacy Remote Settings (games by default will do this). I can investigate further once I’m back in the office on Tuesday.

    If that’s the issue, we’re hoping it’ll be resolved in a future package version where we decouple from the engine APIs for Remote Settings and Remote Config.
     
  3. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    I had my call in Start rather than Awake because I wanted to make sure some things initialized in their own Awakes before it fired. If I move it to Awake then I still get two calls, but the first is cached and the second is remote, and I don't see that blank data callback. Not sure why that fixes it?

    Thanks for the quick reply! And the great talk!
     
    rambod likes this.
  4. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    tried a bunch of different combinations, and here's what I found:

    FetchCompleted += ApplyRemoteSettings
    in Awake, nothing else:
    = Cached callback, then blank Remote callback

    FetchCompleted += ApplyRemoteSettings
    in Start, nothing else:
    = Blank Remote callback

    FetchCompleted += ApplyRemoteSettings
    and
    FetchConfigs
    in Awake:
    = Cached callback, then Remote callback with correct values

    FetchCompleted += ApplyRemoteSettings
    and
    FetchConfigs
    in Start:
    = blank Remote callback, then Remote callback with correct values

    FetchCompleted += ApplyRemoteSettings
    in Awake,
    FetchConfigs
    in Start:
    = Cached callback, then blank Remote callback, then correct Remote callback!

    FetchCompleted += ApplyRemoteSettings
    in Start,
    FetchConfigs
    in Awake:
    = Just one Remote callback with correct values! (WUT)
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    yeah, I'm using ApplyRemoteSettings code that's identical to what's in that example (except with my values instead of those provided). "cached callback" = ApplyRemoveSettings with ConfigOrigin.Cached, and "blank remote callback" = ApplyRemoveSettings with ConfigOrigin.Remote, but all the values in ConfigManager.appConfig are blank.
     
    JeffDUnity3D likes this.
  7. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58

    Okay so did some investigation on our end, and this seems to be due to the in-engine APIs we're using currently. They're also used by the older Remote Settings system. We'll be shipping a new version of the package in the next month or so that de-couples completely from the engine APIs that'll solve the weirdness with these call orderings.

    I guess in the meantime, were you able to get things working? If not, I'm more than happy to hop on a call with you and see what's going on.
     
  8. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    yay! a fix!

    yep, I was able to get it working via that weird configuration I mentioned at the end of my investigations above, which I'll un-weird once the fix arrives.

    Thanks for the quick replies and for looking into this!

    Now I need to track down the "Input System Rambod" for my current Input System woes... :)
     
    vd_unity and rambod like this.
  9. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @luvcraft yay! I'm glad :)

    I'll keep you posted on when the new release is ready!

    Good luck on finding more Rambods, let me know if this Rambod can be of more help!
     
    luvcraft likes this.
  10. dohaiha930

    dohaiha930

    Joined:
    Mar 27, 2018
    Posts:
    55
    Hi, i have the same issue, copy/paste code from documents page, then duplicate fetching happen

    remote-config-bug.PNG

    Code (CSharp):
    1. // Retrieve and apply the current key-value pairs from the service on Awake:
    2.     void Awake () {
    3.         // Add a listener to apply settings when successfully retrieved:
    4.         ConfigManager.FetchCompleted += ApplyRemoteSettings;
    5.  
    6.         // Fetch configuration setting from the remote service:
    7.         ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
    8.     }
    9.  
    10.     void ApplyRemoteSettings (ConfigResponse configResponse) {
    11.         // Conditionally update settings, depending on the response's origin:
    12.         switch (configResponse.requestOrigin) {
    13.             case ConfigOrigin.Default:
    14.                 Debug.Log ("Load fail! Use DEFAULT");
    15.                 break;
    16.             case ConfigOrigin.Cached:
    17.                 Debug.Log ("Load fail! Use Cached");
    18.                 break;
    19.             case ConfigOrigin.Remote:
    20.                 Debug.Log ("Success Load Settings From Server!");
    21.                 break;
    22.         }
    23.     }
    24.  
    Btw: I think it is still working without any problem, cause it's still load success on 2nd.
     
    rambod likes this.
  11. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @dohaiha930 thanks for sharing that as well! Glad the double fetch is consistently reproducible, and that it’s not blocking you from proceeding.
     
    dohaiha930 likes this.
  12. Jumeuan

    Jumeuan

    Joined:
    Mar 14, 2017
    Posts:
    39
    @rambod : On last version 1.0.8, this bug still be there, please fix it, because when it's duplicate my handle methods.
     
  13. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    @Jumeuan and @dohaiha930 this should now be fixed as of `1.1.0-preview`. Let me know if you see it again after moving to a new version
     
    vd_unity likes this.
  14. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    194
    Just saying, the latest verified version for 2019.4 is still version 1.0.9, which has the double callback.
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Make sure you select Show preview packages from the Advanced dropdown in the Package Manager UI. The latest I see as of today is 2.0.1 published Dec 12, I'm using Unity 2019.4.1f1
     
  16. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    194
    Pointed out because the verified versions tend to be much more safer and I want to add this feature to a released game. As much as the new version may work on my side/testers side, I don't know every little details in the package that may bring harm in different scenarios, as much as the developers who wrote it.
     
    Lord_Eniac and JeffDUnity3D like this.
  17. kannan_mk123

    kannan_mk123

    Joined:
    Dec 27, 2021
    Posts:
    3
    still same issue. im getting called 2 times in latest unity 2020.3 version with FetchCompleted calling 2 times.unity please fix this.remote config version 2.1.2
     
    Last edited: Feb 1, 2022
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please test with version 3.0.0-pre.9 and share the code that you are using, we will check.
     
  19. kannan_mk123

    kannan_mk123

    Joined:
    Dec 27, 2021
    Posts:
    3
    sure i will check and get back