Class WebGLPersistentData
Pushes files written under Application.persistentDataPath into the browser's
IndexedDB, so they survive the page being closed.
public static class WebGLPersistentData
- Inheritance
-
WebGLPersistentData
- Inherited Members
Remarks
Why this exists. On WebGL persistentDataPath is an Emscripten IDBFS
mount, which is an in-memory filesystem with IndexedDB behind it. A write reaches memory
immediately and IndexedDB only when the mount is persisted. Unity persists automatically on
file close, but only when the page passes autoSyncPersistentDataPath: true to
createUnityInstance() — this project ships the stock PWA template, which does not.
Without an explicit sync the settings file is written, is read back correctly for the rest
of the session, and has vanished by the next visit. That is indistinguishable, from the
player's side, from settings that are never saved at all.
Everywhere else this is nothing. On a desktop build the method compiles to an empty body, so callers need no platform guard of their own — which is the point. A guard at each call site is a guard somebody forgets to add to the next one.
Methods
Sync()
Requests that pending writes under Application.persistentDataPath be persisted.
public static void Sync()
Remarks
Asynchronous on the browser side and safe to call after every save: the underlying queue coalesces requests and never runs two syncs at once. Failures are reported to the browser console and never thrown — a browser with IndexedDB unavailable must lose settings between sessions rather than fail the save that is holding them for this one.