Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Remote Config callback firing multiple times

Discussion in 'Unity Remote Config' started by wilczarz_84, Aug 30, 2023.

  1. wilczarz_84

    wilczarz_84

    Joined:
    Jan 6, 2017
    Posts:
    21
    I noficed that when I run my game in Unity Editor, the callback for Remote Config is fired many times:



    This is my configuration:
    Code (CSharp):
    1.  
    2. private void Awake ()
    3. {
    4.     UnityServices.InitializeAsync();
    5.  
    6.     TimeManager.RunDelayed(0.5f, () =>
    7.     {
    8.         RemoteConfigService.Instance.FetchCompleted += ApplyRemoteSettings;
    9.         RemoteConfigService.Instance.SetEnvironmentID(ENVIRONMENT_ID);
    10.         RemoteConfigService.Instance.FetchConfigs(new UserAttributes(), new AppAttributes());
    11.     });
    12. }
    13.  
    14. private void ApplyRemoteSettings (ConfigResponse configResponse)
    15. {
    16.     if (configResponse.requestOrigin == ConfigOrigin.Default) Debug.Log("[Remote Config] No settings loaded, using default values.");
    17.     else if (configResponse.requestOrigin == ConfigOrigin.Cached) Debug.Log("[Remote Config] No settings loaded, using cached values from a previous session.");
    18.     else if (configResponse.requestOrigin == ConfigOrigin.Remote) Debug.Log("[Remote Config] New settings loaded, updating the cache.");
    19.  
    20.     UpdateSettings();
    21. }
    22.  
    Any idea why is this happening?
    I am using Unity 2021.3.28f1 with Remote Config 3.3.2.
     
  2. YD_JMysior

    YD_JMysior

    Joined:
    Aug 4, 2016
    Posts:
    59
    Does not happen for me with RC 3.3.2.
    I would check the TimeManager.RunDelayed (perhaps it calls several times) or if the Awake isn't called on multiple objects.
    Also delaying the FetchConfigs by 0.5 second does not sound like a good practice - there is no guarantee it will take less than 0.5 second. Instead make the Awake async and await the UnityServices.InitializeAsync() call - this way the other code will run only after the initialization is completed.