Export to WebGL save / load not working
I have a serlialisable class that I use to persist my data between sessions which works fine on mobile / desktop but does not work when exported to WebGL (Unity 2017)
[Serializable]
public class GameData
{
public float CoinBalance = 0;
public List<int> ItemCounts = new List<int>();
public List<bool> ItemUnlocks = new List<bool>();
public List<int> Upgrades = new List<int>();
public List<int> UpgradeStates = new List<int>();
public List<int> ModStates = new List<int>();
public List<float> PowerupTimers = new List<float>();
public List<bool> AchievementUnlocks = new List<bool>();
}
public void SaveGame()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/gamedata.bin", FileMode.OpenOrCreate);
bf.Serialize(file, GameData);
file.Close();
}
void LoadGame()
{
if (File.Exists(Application.persistentDataPath + "/gamedata.bin"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/gamedata.bin", FileMode.Open);
_GameData = bf.Deserialize(file) as GameData;
file.Close();
}
}
Its all pretty bog standard, but just does not work, no errors or exceptions, just doesn't work.
I have another game exported from Unity 5.4 with similar data that works just fine when exported to WebGL. Has something broken in Unity 2017?
Answer by drmop · Aug 23, 2017 at 10:22 PM
Ok, I don't believe I have to do this in Unity 2017 but I have to resort to calling a bit of Javascript to force the file to sync FS.fsync(). WTF seriously? Anyway, it works but now I get a warning "warning: 2 FS.syncfs operations in flight at once, probably just doing extra work", I'm assuming that it is already getting called somewhere but just not working?
Answer by carenborn · Jul 21, 2018 at 04:53 PM
Is the data saved so you can load the same data on another computer? Or is it just saved on the computer you play on?