Skip to content

Saves and settings last across releases on the web - #142

Merged
h0lybyte merged 1 commit into
mainfrom
fix/save-load
Nov 13, 2026
Merged

h0lybyte merged 1 commit into
mainfrom
fix/save-load

Conversation

@h0lybyte

Copy link
Copy Markdown
Owner

Bug. On itch.io every release started with empty save slots and default settings.

Cause. Unity's WebGL PlayerPrefs live in IndexedDB under /idbfs/<md5 of the page's folder URL>/PlayerPrefs. I checked this locally: the hash is the md5 of origin + folder, and the query string and file name don't change it. itch serves each upload from a new folder (currently html-classic.itch.zone/html/20387758-2378538/), so each build looked under a new hash. Within one build, saves did work.

Fix.

  • LocalStore (with LocalStore.jslib) keeps saves and settings in localStorage under luckynumbers.*. Every itch HTML game is served from one origin, so the prefix matters. localStorage doesn't depend on the folder.
  • PlayerPrefs stay as a second copy, and as the fallback when storage is blocked. A key that only PlayerPrefs has moves across the first time it's read. Outside the browser (editor, desktop), PlayerPrefs are used alone.
  • SavePresenter and SettingsPresenter now go through LocalStore.
  • Rescue for existing players: before Unity starts, index.html checks this build's folder. If it has no PlayerPrefs yet, the page copies in the newest PlayerPrefs another build left. Those slots then show up and move to localStorage. The rescue is capped at 1.5 s, so it never blocks the start for long.

Testing

  • ln.py check: 0 errors. ln.py tests: 77/77 passed.
  • Headless Web build. To fake an older build, I served the same build from a second folder (/old/) on the same origin, all in one browser profile:
    1. In /old/, I made a new character in slot 1. It was written to localStorage as luckynumbers.ln.save.0.
    2. I cleared localStorage, so only the old folder's PlayerPrefs held the save, as with 0.4.1 and earlier.
    3. Loading /index.html logged [web] saves: carried over from an older build (/idbfs/155f…).
    4. Slot 1 showed in the picker and was back in localStorage.
    5. Continue logged [Save] loaded slot 1: Salvager … Station.
  • The JS md5 matches macOS md5 on the localhost URL and on the itch folder URL.

Unity's WebGL PlayerPrefs live in IndexedDB under /idbfs/<md5 of the page's
folder URL>. itch.io serves each upload from a new folder
(html/<build>-<upload>/), so every release started with empty save slots and
default settings: the old ones were still there, under another hash.

LocalStore keeps saves and settings in the browser's localStorage (prefix
"luckynumbers.", since itch serves every HTML game from one origin), which
doesn't depend on the folder. PlayerPrefs stay as a second copy and the
fallback when storage is blocked; a key only PlayerPrefs has moves across when
first read.

For saves made before this: the page, before Unity starts, copies the newest
PlayerPrefs another build left into this build's folder if it has none yet, so
those slots show up and move to localStorage.
@h0lybyte
h0lybyte merged commit c5c15e4 into main Nov 13, 2026
1 check passed
@h0lybyte
h0lybyte deleted the fix/save-load branch November 13, 2026 22:21
@h0lybyte h0lybyte mentioned this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant