Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Saving game data for web based games hosted in itch.io and built in Unity

I recently noticed that player' game data was being lost between updates. My game MurderDeathKill is hosted on itch.io and built in Unity (WebGL). The reason turned out to be that game data is saved in IndexedBD and the path used by Application.persistentDataPath has a GUID as part of the path which is updated on each new build. The fix was to set the path for WebGL builds instead of using Application.persistentDataPath 


    private string GetSavePath(string filename)
    {
        var path = Application.persistentDataPath;
        #if UNITY_WEBGL && !UNITY_EDITOR
         path = "/idbfs/murder-death-kill";
          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;
    }

Hope this helps. You can play Murder Death Kill at https://codedragons.itch.io/murder-death-kill

Support this post

Did you like this post? Tell us

In this post

Leave a comment

Log in with your itch.io account to leave a comment.

Mentioned in this post

2D RPG puzzle adventure that will keep you on the edge of your seat
Adventure
Play in browser