Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity Remote Config return wrong "time" string

Discussion in 'Unity Remote Config' started by tung0997tn, Oct 31, 2021.

  1. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    I created a string variable in unity dash board that looks like the first line
    "2021-10-22T00:00:00.0000001+07:00".
    Its a time sring that i can parse to DateTime using DateTime.ParseExact. But the string i got from unity remote is the second line "10/22/2021 00:00:00".
    I get that string in the editor normally but on the phone it becomes the wrong string like that.
    I don't know if remote config did it accidentally or on purpose but it makes me very uncomfortable.
     

    Attached Files:

  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @tung0997tn Can you share the code you are using, and a screenshot of this value on your RC dashboard?
     
  3. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Here is a part of my scripts and a screenshot of value call "missionRockStartDay".
     

    Attached Files:

  4. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Code (CSharp):
    1. private void Awake()
    2.     {
    3.         gameManager = GameManager.Instance;
    4.         missionData = MissionData.Instance;
    5.         ConfigManager.FetchCompleted += ApplyConfigData;
    6.         if (isDevelopment) ConfigManager.SetEnvironmentID(developmentEvironmentID);
    7.         else ConfigManager.SetEnvironmentID(productionEvironmentID);
    8.     }
    9.  
    10.     public void FetchRemoteConfig()
    11.     {
    12.         isLoaded = false;
    13.         ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
    14.     }
    15.  
    16.     protected override void OnDestroy()
    17.     {
    18.         ConfigManager.FetchCompleted -= ApplyConfigData;
    19.     }
    20.  
    21.     void ApplyConfigData(ConfigResponse response)
    22.     {
    23.         if(response.status == ConfigRequestStatus.Success)
    24.         {
    25.             StartCoroutine(WaitToLoadConfigData(response));
    26.         }
    27.         else if(response.status == ConfigRequestStatus.Failed)
    28.         {
    29.             Intro.Instance.LoadOfflineMode();
    30.         }
    31.         else if(response.status == ConfigRequestStatus.Pending || response.status == ConfigRequestStatus.None)
    32.         {
    33.             Intro.Instance.Reconnecting();
    34.         }
    35.     }
    36.  
    37.     IEnumerator WaitToLoadConfigData(ConfigResponse response)
    38.     {
    39.         switch (response.requestOrigin)
    40.         {
    41.             case ConfigOrigin.Default:
    42.                 Debug.Log("No settings loaded this session; using default values.");
    43.                 break;
    44.             case ConfigOrigin.Cached:
    45.                 Debug.Log("No settings loaded this session; using cached values from a previous session.");
    46.                 break;
    47.             case ConfigOrigin.Remote:
    48.                 Debug.Log("New settings loaded this session; update values accordingly.");
    49.  
    50.                 //=======Mission=======
    51.  
    52.                 missionData.daysCycle = ConfigManager.appConfig.GetInt("daysPerCycle");
    53.                 missionData.missionInfos[0].startTime = ConfigManager.appConfig.GetString("missionRockStartDay");
    54.                 missionData.missionInfos[0].missionLength = ConfigManager.appConfig.GetInt("missionRockLength");
    55.                 missionData.missionInfos[1].startTime = ConfigManager.appConfig.GetString("missionMermaidStartDay");
    56.                 missionData.missionInfos[1].missionLength = ConfigManager.appConfig.GetInt("missionMermaidLength");
    57.                 missionData.missionInfos[2].startTime = ConfigManager.appConfig.GetString("missionFireflyStartDay");
    58.                 missionData.missionInfos[2].missionLength = ConfigManager.appConfig.GetInt("missionFireflyLength");
    59.  
    60.                 break;
    61.         }
    62.         yield return null;
    63.         if (!isLoaded)
    64.         {
    65.             if (Intro.Instance != null) Intro.Instance.LoadGameScene();
    66.             isLoaded = true;
    67.         }
    68.     }
    69.  
     
  5. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Code (CSharp):
    1. public void InitializeDate()
    2.     {
    3.         for (int i = 0; i < missionData.missionInfos.Count; i++)
    4.         {
    5.     //This is line of code use "missionRockStartDay" fetch from RC dashboard and always false on mobile because "missionRockStartDay" isn't a time string
    6.             missionStartTime[i] = DateTime.ParseExact(missionData.missionInfos[i].startTime, "O", CultureInfo.InvariantCulture);
    7.     //
    8.  
    9.             if ((DateTime.Now - missionStartTime[i]).TotalSeconds % allMissionCycleToSeconds < missionLengthToSeconds[i])
    10.             {
    11.                 DateTime thisMissionStartTime = missionStartTime[i].AddDays(Mathf.FloorToInt((float)((DateTime.Now - missionStartTime[i]).TotalSeconds / allMissionCycleToSeconds)) * missionData.daysCycle);
    12.                 if (!missionData.missionInfos[i].lastMission.Equals(thisMissionStartTime.ToString("O")))
    13.                 {
    14.                     "Some thing"
    15.                 }
    16.             }
    17.             else
    18.             {
    19.  
    20.                 "Some thing"
    21.             }
    22.         }
    23.         isInitialized = true;
    24.     }
    25.  
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you show your definition for missionData.missionInfos[0].startTime , is it just a String datatype?
     
  7. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Code (CSharp):
    1. public class MissionData : ScriptableObject
    2. {
    3.     private static MissionData instance;
    4.     public static MissionData Instance
    5.     {
    6.         get
    7.         {
    8.             if (instance == null) instance = Resources.Load<MissionData>("MissionData");
    9.             return instance;
    10.         }
    11.     }
    12.  
    13.     public int daysCycle;
    14.     public List<MissionInfo> missionInfos = new List<MissionInfo>();
    15. }
    16.  
    17. [System.Serializable]
    18. public class MissionInfo
    19. {
    20.     public int missionId;
    21.     public string missionName;
    22.     public string startTime;
    23.     public int missionLength;
    24.     public int maxValue;
    25.     public int gems;
    26.     public float coinsPerLevel;
    27.     public string lastMission;
    28.     public int count;
    29.     public bool wasSet;
    30. }
    31.  
    Yeah, It is just a string in a Scriptable Object.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, we are checking.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @tung0997tn So far, we have not been able to reproduce. The string we put in is the same that we pull out. As a test, can you try:

    string myString = ConfigManager.appConfig.GetString("missionRockStartDay", "test");
    Debug.Log("myString = " + myString.ToString());
     
  10. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using Unity.RemoteConfig;
    6.  
    7. public class TestRemoteConfig : MonoBehaviour
    8. {
    9.     [SerializeField] private Text debugText;
    10.  
    11.     public struct userAttributes { }
    12.     public struct appAttributes { }
    13.  
    14.     private const string developmentEvironmentID = "";
    15.  
    16.     private void Awake()
    17.     {
    18.         ConfigManager.FetchCompleted += ApplyConfigData;
    19.         ConfigManager.SetEnvironmentID(developmentEvironmentID);
    20.     }
    21.  
    22.     private void Start()
    23.     {
    24.         FetchRemoteConfig();
    25.     }
    26.  
    27.     public void FetchRemoteConfig()
    28.     {
    29.         ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
    30.     }
    31.  
    32.     private void OnDestroy()
    33.     {
    34.         ConfigManager.FetchCompleted -= ApplyConfigData;
    35.     }
    36.  
    37.     void ApplyConfigData(ConfigResponse response)
    38.     {
    39.         if (response.status == ConfigRequestStatus.Success)
    40.         {
    41.             StartCoroutine(WaitToLoadConfigData(response));
    42.         }
    43.         else if (response.status == ConfigRequestStatus.Failed)
    44.         {
    45.             MyDebug("Connect Failed");
    46.  
    47.         }
    48.         else if (response.status == ConfigRequestStatus.Pending || response.status == ConfigRequestStatus.None)
    49.         {
    50.             MyDebug("Connect Pending or None");
    51.             FetchRemoteConfig();
    52.         }
    53.     }
    54.  
    55.     IEnumerator WaitToLoadConfigData(ConfigResponse response)
    56.     {
    57.         switch (response.requestOrigin)
    58.         {
    59.             case ConfigOrigin.Default:
    60.                 MyDebug("No settings loaded this session; using default values.");
    61.                 break;
    62.             case ConfigOrigin.Cached:
    63.                 MyDebug("No settings loaded this session; using cached values from a previous session.");
    64.                 break;
    65.             case ConfigOrigin.Remote:
    66.                 MyDebug("New settings loaded this session; update values accordingly.");
    67.  
    68.                 string myOldString = ConfigManager.appConfig.GetString("missionRockStartDay");
    69.                 MyDebug("myOldString = " + myOldString.ToString());
    70.  
    71.                 string myString = ConfigManager.appConfig.GetString("missionRockStartDay", "test");
    72.                 MyDebug("myString = " + myString.ToString());
    73.  
    74.  
    75.  
    76.                 break;
    77.         }
    78.         yield return null;
    79.     }
    80.  
    81.     private void MyDebug(string text)
    82.     {
    83.         Debug.Log(text);
    84.         debugText.text += "\r\n" + text;
    85.     }
    86. }
    87.  
    This is my test script i use your suggestion. On editor it work but on my phone it go wrong. I have attached a few pictures below. I found another solution to my problem but maybe this is still a remote config problem. Hopefully this issue will be resolved in future updates.
     

    Attached Files:

  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @tung0997tn What version of RC are you using? Your EnvironmentID is an empty string, you need to specify a value. We have not been able to reproduce so there is no action for us to take so far. Can you describe your solution?
     
  12. vd_unity

    vd_unity

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    37
    @tung0997tn ,

    If this helps, we had that bug fixed within
    ## [1.2.4-preview.3] - 2020-08-17
    - Fixed bug where Json.net unexpectedly formats date-looking string to Date by default

    Namely, this was the case if someone used a date looking string as a setting in the editor, json.net would format it to date by default.
    It was design decision from json.net team, and many other users were surprised with this string-to-date reformatting, as in
    https://github.com/JamesNK/Newtonsoft.Json/issues/862
    Once we realized that, we implemented fix immediately.

    Possible reason why it works for you in the editor, but not on the device could be that build on the device was made with RC version before the fix (< 1.2.4-preview.3)
    We would be curious to know which RC version was used to make your build, and on what kind of device?

    Thanks!
     
    JeffDUnity3D likes this.
  13. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    I use Remote Config version 2.1.2 and i have hidden EnvironmentID, it is not an empty string.
     
    vd_unity likes this.
  14. tung0997tn

    tung0997tn

    Joined:
    Feb 10, 2020
    Posts:
    8
    Thanks, I understood the problem.
     
    vd_unity likes this.