- Home /
Question by
mendrak · Jan 29 at 02:19 AM ·
persistence
WebGL data persistence
How do I perform data persistence in a WebGL build of an application with multiple targets (such as native and WebGL). I am perfectly happy with the persistent data being different from browser instance to browser instance so the IndexDB technique that seems to underlay the File class in a WebGL build would be fine.
When I do the following to read the value.
string json = JsonUtility.ToJson(CurrentHighScore);
File.WriteAllText(Application.persistentDataPath + "/savefile.json", json);
And then update it later
string result = File.ReadAllText(Application.persistentDataPath + "/savefile.json");
HighScore scoreResult = JsonUtility.FromJson<HighScore>(result);
The data is not updated after the first time (tested with WebGL on Unity Play). It always returns the value originally saved.
Comment
Sorry I reversed my code samples. The first chunk is where I write and the second chunk is where I read.
BTW the code works fine under a native windows build.