Posted July 05, 2021 by DDmeow
#saving #persistent #WebGL #unity #devlog
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.
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.
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);
}
The save file is saved in the player’s browser. So,
Brackeys’s SAVE & LOAD SYSTEM in Unity
originally from my blog: