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. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here:
    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
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

Question Remote Config Returns ConfigOrigin.Remote When Offline with no Cache

Discussion in 'Unity Remote Config' started by Heero888, Jun 2, 2022.

  1. Heero888


    Jun 18, 2017

    I am seeing remote config returns ConfigOrigin.Remote when device is offline. Is this normal?

    Below is my code and what i am trying to do:
    1) When the device is online, Remote Config would work perfectly and everything is fine.

    2) When the device is online, I delete Remote Config cache with my own code after Remote Config finishes its magic. The reason i do this is to make player harder to cheat.

    3) When the device is offline, Remote Config will not able to read any cache since I always delete that.

    4) When the device is offline, GetData(ConfigResponse configResponse) return ConfigOrigin.Remote, which I would expect it returns .Default since there is no cache and Offline.

    If I keep the cache there things would work. But I really want to keep that cache out of the device. Is there a way to tell RemoteConfig to return ConfigOrigin.Default when the device is offline in my case? Or is there a better way to do to what i want to achieve?

    Thank you!

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using Unity.RemoteConfig;
    4. using System.IO;
    6. public class RemoteConfigController : MonoBehaviour
    7. {
    8.      [Tooltip("this delay is mainly for incase there is a loading and saving operations in other scripts so it wait a little bit before reading server")]
    9.      private float startDelay = 0.2f;
    10.      [HideInInspector] public struct UserAttribute { }
    11.      [HideInInspector] public struct AppAttributes { }
    13.      #region Singleton
    14.      public static RemoteConfigController instance;
    15.      private void Awake()
    16.      {
    17.          if (instance != null)
    18.          {
    19.              Destroy(instance.gameObject);
    20.          }
    21.          instance = this;
    22.          DontDestroyOnLoad(this);
    23.      }
    24.      #endregion
    26.      private void Start()
    27.      {
    28.          ConfigManager.FetchCompleted += GetData;
    29.          StartCoroutine(FetchDataCoroutine());
    30.      }
    32.      IEnumerator FetchDataCoroutine()
    33.      {
    34.          yield return new WaitForSeconds(startDelay);
    35.          ConfigManager.SetEnvironmentID("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    36.          ConfigManager.FetchConfigs<UserAttribute, AppAttributes>(new UserAttribute(), new AppAttributes());
    37.      }
    39.      private void GetData(ConfigResponse configResponse)
    40.      {
    41.          switch (configResponse.requestOrigin)
    42.          {
    43.              case ConfigOrigin.Default:
    44.                  Debug.Log("ConfigOrigin = Default.");
    45.                  break;
    46.              case ConfigOrigin.Cached:
    47.                  Debug.Log("ConfigOrigin = Cached.");
    48.                  break;
    49.              case ConfigOrigin.Remote:
    50.                  Debug.Log("ConfigOrigin = Remote.");
    51.                  break;
    52.          }
    53.          StartCoroutine(DeleteRemoteConfigCache());
    54.      }
    56.      IEnumerator DeleteRemoteConfigCache()
    57.      {
    58.          //using delay because the file cannot be deleted at the exact moment after it was created/modified
    59.          yield return new WaitForSeconds(0.1f);
    60.          //check if cache file exist, if so delete the cache file
    61.          string path = Application.persistentDataPath + "/RemoteConfigCache.json";
    62.          if (File.Exists(path))  //check if file exists
    63.          {
    64.              File.Delete(path);
    65.              Debug.Log("Deleted " + path);
    66.          }
    67.      }
    68. }
    Last edited: Jun 2, 2022
  2. SebT_Unity


    Unity Technologies

    Jun 21, 2021
    Hi there!
    Thanks for posting on the forums.

    When possible could you confirm the version of Remote config you are running? This will help us guide you to a better solution.

    We look forward to your response.

  3. Heero888


    Jun 18, 2017
    Thanks for your reply.

    I am using RemoteConfig 2.1.2 with Unity 2019.4.37f
  4. JeffDUnity3D


    Unity Technologies

    May 2, 2017
    Please test with RC 3.0.0-pre.15, this has been addressed in recent releases.
  5. Heero888


    Jun 18, 2017
    updating works! thank you!
    SebT_Unity and JeffDUnity3D like this.
  6. PeachyPixels


    Feb 17, 2018
    Hey @JeffDUnity3D

    I've just updated from 2.1.2 to 3.1.3 and noticed the following behaviour...

    1. Device Online
    2. Open Game
    3. FetchConfigs -> RemoteSettingsFetched (Origin = Remote, Status = Success)
    4. Exit Game
    5. Device Offline
    6. Open Game
    7. FetchConfigs -> RemoteSettingsFetched (Origin = Cached, Status = Failed)

    Step 7 might be by design, but doesn't feel right to me. It implies the cached values failed.

    I'm wondering if either of the following scenarios might be better...

    7. FetchConfigs -> RemoteSettingsFetched (Origin = Remote, Status = Failed)
    8. FetchConfigs -> RemoteSettingsFetched (Origin = Cached, Status = Success)

    NOTE: One call, but two events rasied.


    7. FetchConfigs -> RemoteSettingsFetched (Origin = Cached, Status = Success)

    Preferably the former as it's more representative of what actually happened.

    Not a deal breaker and it makes no odds to my implementation as I call appConfig.GetX(<name>, <default>) (regardless of Status) in the event handler (so the defaults are always applied as a fallback)

    Just an observation anyway. Hope it makes sense.
  7. JeffDUnity3D


    Unity Technologies

    May 2, 2017
    We probably don't want to have two events raised at the same time. Why would you expect both Remote and Cached being called for the same call? If we returned Success every time, there would be no need for the return code. But your point is taken regarding Failed when Cached was indeed "successful" in loading the cached values, I will pass this along.
    PeachyPixels likes this.
  8. PeachyPixels


    Feb 17, 2018
    The two events idea was more so the developer is aware that the Remote origin failed. That said, I understand you could argue it's implied if the Cached or Defaults origin is used so yes, maybe it's overkill :)

    But changing the status from Failed to Successful would be good too. Thanks! :)