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.
@tung0997tn Can you share the code you are using, and a screenshot of this value on your RC dashboard?
Here is a part of my scripts and a screenshot of value call “missionRockStartDay”.
7618828–947167–RemoteConfigManager.txt (2.73 KB)
7618828–947173–MissionController.txt (1.04 KB)
private void Awake()
{
gameManager = GameManager.Instance;
missionData = MissionData.Instance;
ConfigManager.FetchCompleted += ApplyConfigData;
if (isDevelopment) ConfigManager.SetEnvironmentID(developmentEvironmentID);
else ConfigManager.SetEnvironmentID(productionEvironmentID);
}
public void FetchRemoteConfig()
{
isLoaded = false;
ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
}
protected override void OnDestroy()
{
ConfigManager.FetchCompleted -= ApplyConfigData;
}
void ApplyConfigData(ConfigResponse response)
{
if(response.status == ConfigRequestStatus.Success)
{
StartCoroutine(WaitToLoadConfigData(response));
}
else if(response.status == ConfigRequestStatus.Failed)
{
Intro.Instance.LoadOfflineMode();
}
else if(response.status == ConfigRequestStatus.Pending || response.status == ConfigRequestStatus.None)
{
Intro.Instance.Reconnecting();
}
}
IEnumerator WaitToLoadConfigData(ConfigResponse response)
{
switch (response.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log("No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
Debug.Log("New settings loaded this session; update values accordingly.");
//=======Mission=======
missionData.daysCycle = ConfigManager.appConfig.GetInt("daysPerCycle");
missionData.missionInfos[0].startTime = ConfigManager.appConfig.GetString("missionRockStartDay");
missionData.missionInfos[0].missionLength = ConfigManager.appConfig.GetInt("missionRockLength");
missionData.missionInfos[1].startTime = ConfigManager.appConfig.GetString("missionMermaidStartDay");
missionData.missionInfos[1].missionLength = ConfigManager.appConfig.GetInt("missionMermaidLength");
missionData.missionInfos[2].startTime = ConfigManager.appConfig.GetString("missionFireflyStartDay");
missionData.missionInfos[2].missionLength = ConfigManager.appConfig.GetInt("missionFireflyLength");
break;
}
yield return null;
if (!isLoaded)
{
if (Intro.Instance != null) Intro.Instance.LoadGameScene();
isLoaded = true;
}
}
public void InitializeDate()
{
for (int i = 0; i < missionData.missionInfos.Count; i++)
{
//This is line of code use "missionRockStartDay" fetch from RC dashboard and always false on mobile because "missionRockStartDay" isn't a time string
missionStartTime[i] = DateTime.ParseExact(missionData.missionInfos[i].startTime, "O", CultureInfo.InvariantCulture);
//
if ((DateTime.Now - missionStartTime[i]).TotalSeconds % allMissionCycleToSeconds < missionLengthToSeconds[i])
{
DateTime thisMissionStartTime = missionStartTime[i].AddDays(Mathf.FloorToInt((float)((DateTime.Now - missionStartTime[i]).TotalSeconds / allMissionCycleToSeconds)) * missionData.daysCycle);
if (!missionData.missionInfos[i].lastMission.Equals(thisMissionStartTime.ToString("O")))
{
"Some thing"
}
}
else
{
"Some thing"
}
}
isInitialized = true;
}
Can you show your definition for missionData.missionInfos[0].startTime , is it just a String datatype?
public class MissionData : ScriptableObject
{
private static MissionData instance;
public static MissionData Instance
{
get
{
if (instance == null) instance = Resources.Load<MissionData>("MissionData");
return instance;
}
}
public int daysCycle;
public List<MissionInfo> missionInfos = new List<MissionInfo>();
}
[System.Serializable]
public class MissionInfo
{
public int missionId;
public string missionName;
public string startTime;
public int missionLength;
public int maxValue;
public int gems;
public float coinsPerLevel;
public string lastMission;
public int count;
public bool wasSet;
}
Yeah, It is just a string in a Scriptable Object.
Got it, we are checking.
@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());
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Unity.RemoteConfig;
public class TestRemoteConfig : MonoBehaviour
{
[SerializeField] private Text debugText;
public struct userAttributes { }
public struct appAttributes { }
private const string developmentEvironmentID = "";
private void Awake()
{
ConfigManager.FetchCompleted += ApplyConfigData;
ConfigManager.SetEnvironmentID(developmentEvironmentID);
}
private void Start()
{
FetchRemoteConfig();
}
public void FetchRemoteConfig()
{
ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
}
private void OnDestroy()
{
ConfigManager.FetchCompleted -= ApplyConfigData;
}
void ApplyConfigData(ConfigResponse response)
{
if (response.status == ConfigRequestStatus.Success)
{
StartCoroutine(WaitToLoadConfigData(response));
}
else if (response.status == ConfigRequestStatus.Failed)
{
MyDebug("Connect Failed");
}
else if (response.status == ConfigRequestStatus.Pending || response.status == ConfigRequestStatus.None)
{
MyDebug("Connect Pending or None");
FetchRemoteConfig();
}
}
IEnumerator WaitToLoadConfigData(ConfigResponse response)
{
switch (response.requestOrigin)
{
case ConfigOrigin.Default:
MyDebug("No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
MyDebug("No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
MyDebug("New settings loaded this session; update values accordingly.");
string myOldString = ConfigManager.appConfig.GetString("missionRockStartDay");
MyDebug("myOldString = " + myOldString.ToString());
string myString = ConfigManager.appConfig.GetString("missionRockStartDay", "test");
MyDebug("myString = " + myString.ToString());
break;
}
yield return null;
}
private void MyDebug(string text)
{
Debug.Log(text);
debugText.text += "\r\n" + text;
}
}
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.
@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?
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
Json.NET interprets and modifies ISO dates when deserializing to JObject · Issue #862 · JamesNK/Newtonsoft.Json · GitHub
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!
I use Remote Config version 2.1.2 and i have hidden EnvironmentID, it is not an empty string.
Thanks, I understood the problem.