How To Make Your Save Persistent Through Different Builds At itch.io (Unity's WebGL)


Save Persistent Path Problem

It is taught that Unity’s “Application.persistentDataPath” will persist through different builds. That’s the case for desktop builds. However, if you’re uploading your builds to itch.io (or maybe some other platforms too), the URL that host the build will change every time you upload a new build. Hence, “Application.persistentDataPath” will change every time the game is updated. And the old save will be gone.

Solution To Save Persistent Path Problem

To solve that, use an absolute path for all your builds. Replace “Application.persistentDataPath” with “idbfs/YOUR_GAME_RANDOM_CODE”. I’d add some random codes like “sgwhf94hgfw” at the end just in case someone else is making a game with the same name and using the same method for saving.

PersistentDataPath returns different paths for different builds <-I actually found the answer here first, then added my own solutions to it when more problems popped up.

Create The Path

As you’re using your own defined path, Unity won’t create the path for you, so you’ll have to generate the path yourself. Just put this before you use the path:

if (!Directory.Exists(savePathName))
{
Directory.CreateDirectory(savePathName);
}

Additional Note Of WebGL save

The save file is saved in the player’s browser. So,

  1. The save will be gone if the player clears the browser’s data.
  2. If the player switch browser or computer, the old save will not be there.

Related To Saving:

Brackeys’s SAVE & LOAD SYSTEM in Unity

originally from my blog:

https://ddmeow.net/en/game-dev/save-persistent-itch-io/

Files

Build.zip Play in browser
Jun 27, 2021

Leave a comment

Log in with itch.io to leave a comment.