Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits) (+2)

Hi SteBee, I ran into this problem as well, however I believe there is an easier solution:

https://itch.io/t/140214/persistent-data-in-updatable-webgl-games

I'm no web developer, but it seems like we can write to any folder inside the  browser's "idbfs" directory. I did something like this:

private string GetSavePath(string filename) {
         var path = Application.persistentDataPath;
  #if UNITY_WEBGL && !UNITY_EDITOR
         path = "/idbfs/YourGameNameOrAnythingHere";
          if (!Directory.Exists(path)) {
             Directory.CreateDirectory(path);
             Debug.Log("Creating save directory: " + path);
         }
 #endif
         var result = Path.Combine(path, filename);
         Debug.Log("Save path: " + result);
         return result;
}

Then you can use C#'s easy to use FileStream, BinaryFormatter, File.Open(...) etc APIs to serialize class data as usual.

I've confirmed this works with my little (soon to be released) Unity (2021.3) WebGL game that new builds correctly persist data as expected.

Verified in Chrome and Edge on Windows and Safari on macOS and iOS.

Hope this helps!

(+1)

Hi Paul, 

Thanks a lot for your solution.
I will try this with my next game.
Looks much easier than my workaround and should avoid a lot of problems on other webpages as well.

Thanks again and kind regards,

SteBee