just wanted to point out an easy way to persistently save files to the browsers IndexedDB using ES3.
I needed this for my work since save files went over the PlayerPref limit and I am not sure why but it seems to be unsupported by default?
see
"However, on WebGL data will automatically be stored in PlayerPrefs regardless of what the location is set to as File IO is not allowed for security reasons."
- https://docs.moodkie.com/easy-save-3/es ... -location/
-------------------------------------------------------------------------------------------------------
All you need to do to allow File Saves on WebGL using ES3 is:
1.) comment out the line of code that defaults to Player Prefs:
ES3Settings.cs line 88 and following:
Code: Select all
public ES3.Location location
{
get
{
//if(_location == ES3.Location.File && (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.tvOS))
//return ES3.Location.PlayerPrefs;
return _location;
}
set{ _location = value; }
}
ES3 does this by default, so you dont need to change anything here, unless you use a custom save path.
If you use a custom path, make sure it starts with "idbfs/"
3.) force flush changes made to the IndexedDB:
Unity does not persistenly save changes done to the IndexedDB path by itself, you need to flush the changes ES3 does here.
Look here for a great answer by JJJohan that saved me a lot of time:
https://forum.unity.com/threads/how-doe ... gl.390385/
The FS.syncfs method in jslib environment is a life saver, just define a function in a .jslib file under Assets/Plugins that calls
FS.syncfs(false,function (err) {}), then import that function in c# and execute it after saving through ES3
With this, ES3 will persistently save your files into the users Browser (IndexedDB), and be able to load from it even after the Application is closed and restarted
(Note, the webgl persistent path (Application.persistentDataPath) changes after every Build, it persistently saves seperately for every version of your app!
If you want to persistently save files even through version updates of your application, make sure you save to an own custom path that starts with "idbfs/", like for instance "idbfs/yourcompany/yourapplication")
----------------------------------------------------
Summary:
To persistently save files on the users computer in a WebGL App that uses ES3:
- Remove the 2 lines at the ES3Settings.cs location getter, where WebGL is excluded from File saving
- Make sure you are saving to the IndexedDB (Application.persistentDataPath, or the ES3 default, or any path that starts with "idbfs/")
- Add a force flush for the IndexedDB after your save function
even all generic System.IO writing functions can persistenly save data for WebGL apps on the users computer following point 2) and 3)