WebGL Filesystem?

I’ve done some test with Application.persistentDataPath in WebGL. I can read / write without any problem. But I don’t understand where my data is.

I can’t find any anwsers, I’ve read that is problably using IndexedDB. Anyone can explain me how the filesystem work for WebGL?

Thanks!

It should indeed work to use .NET File I/O to write to IndexedDB - not even intentionally on our side, but simply because IL2CPP implements .NET File I/O on top of posix file functions, and emscripten implements those on top of IndexedDB. However, because posix file io is synchronous (you can call fread and have it block until you get a result), and IndexedDB is not, emscripten will cache file I/O locally in memory. You may need to call

FS.syncfs(false, function (err) {
    });

To flush cached file writes to IndexedDB. Let us know if it works.

8 Likes

Oh, just if it wasn’t clear, the above called is JavaScript, so you’d need to call it through Application.ExternalCall or using a .jslib file.

I want to bump this thread to confirm what Jonas mentioned, calling FS.syncfs in javascript is necessary for persistent storage to survive between different launches of the app. You’ll need to stick that code into a javascript (browser javascript) and call it via Application.ExternalCall after you finish writing to your file. It does work however, and works quite well!

2 Likes