System.IO.File doesn't work properly on WebGL platform

I’m trying to save player’s data on WebGL platform but File.WriteAllBytes and File.WriteAllText works only in Awake any further calls just doesn’t work and there’s no exceptions in console. Everything works perfectly on other platforms (Editor, desktop mono, desktop il2cpp, android mono, android il2cpp, etc). I’m missing something?

Unity version: 2022.1.7f1

// Test code
public class Tester : MonoBehaviour
{
    private void Awake()
    {
         // Works
        File.WriteAllText(Path.Combine(Application.persistentDataPath, "save_0.dat"), "some data");
    }

    private void Update()
    {
         // Doesn't work
        if (Input.GetKeyDown(KeyCode.Space))
            File.WriteAllText(Path.Combine(Application.persistentDataPath, "save_1.dat"), "some data");
    }
}

system.io is not supported on WebGL. There’s no file system in a browser.

I’ve managed to fix it:

#if UNITY_WEBGL
            Application.ExternalEval("_JS_FileSystem_Sync();");
#endif
1 Like

That’s a fantastic solution.
I’m having the same issue trying to make an existing app work for webgl.
Can you post a more complete code of how the entire script looks with the fix.

Cheers