Can't seem to reload between runs
Posted: Mon Apr 02, 2018 2:22 am
I don't know what I'm doing wrong.. I'm trying to store a list or array of data. If I'm running it works fine, I can load and save and the number of toons seems correct. However when I stop playing and restart, on the initial load the list comes back empty every time. I can see the data in the JSON save file is there. This is just the one part of the save, it does the file.Sync() call later on. I tried implementing it as a List<ToonState> and array ToonState[] and it does the same thing either wayy
Code: Select all
public void LoadFromFile(ES3File file)
{
// destroy any child objects, we'll recreate them on map loads
UnityExtensions.SafeDestroyAllChildren(gameObject);
if (file.KeyExists("Toons"))
{
file.LoadInto<ToonState[]>("Toons", toonStates); // toonStates loads the array fine until i stop playing and after restart it's always empty
}
else
{
toonStates = new ToonState[0];
}
Refresh();
}
public void SaveToFile(ES3File file)
{
UpdateToonStates();
file.Save<ToonState[]>("Toons", toonStates);
}
Code: Select all
{"Toons":{"__type":"Villain.ToonState[],Assembly-CSharp","value":[{"ToonName":"Burly Guard","IsMale":true,"Position":{"x":31.81852,"y":21.04839,"z":0}},{"ToonName":"Burly Guard","IsMale":true,"Position":{"x":35.71773,"y":25.06328,"z":0}}]},"DayNightGameState":{"__type":"Villain.DayNightGameState,Assembly-CSharp","value":{"IsDaytime":true,"DayOfWeek":0,"HourOfDay":7,"MinuteOfDay":46,"deltaTime":0}}}