So I recently learned that when you save files to the file system using persistent data path in a webgl build, it writes them to indexdb. It does not however write them right away, it does so at some point in the future, so if you use it to save game progress, it can be unreliable unless you immediately force it to flush those saves to indexdb.
What is the current best practice to do so? All research I’ve done has pointed to:
Application.ExternalEval("FS.syncfs(false, function (err) {})");
Application.ExternalEval is obsolete.
Ok, I figured this out so I figured I’d leave this here for anyone else, this may not be the only way but it works. I created a .jslib file and put it in assets/plugins withe the contents:
mergeInto(LibraryManager.library, {
syncDB: function() {
FS.syncfs(false, function (err) {});
},
});
Then I called it from my c# code with this include:
using System.Runtime.InteropServices;
This function definition:
[DllImport("__Internal")]
private static extern void syncDB();
and this to call it:
syncDB();
I got lucky guessing and trying stuff, I don’t see this documented clearly anywhere. I still have no idea where FS.syncfs is.