🤑 Indie game store🙌 Free games😂 Fun games😨 Horror games
👷 Game development🎨 Assets📚 Comics
🎉 Sales🎁 Bundles

Persistent Data in (updatable) WebGL games

A topic by DynamiteWhale created 76 days ago Views: 194 Replies: 4
Viewing posts 1 to 5
(Edited 1 time) (+1)

Hello Everyone,


I have spent some time trying to find a good solution for saving game-data (e.g. save games) in a way that persists also after an update on itch.io.

So far my experiments on itch have revealed the following - and please correct me if I am wrong on this:

Any update of a game (even when uploading the same zip/build as an update), will put the game into a different domain (not sure if this is the right word). What I mean is, that any data stored in an indexedDB (afaik Unity also uses indexedDB to store playerprefs), will not be accessible after the update anymore because the browser treats this as a "new" instance the game.

This only leaves some unconvinient options to store playerdata:

  1. Host own user accounts. Players can create an account with a username, and the game will save game data on a 3rd party server. Players can retrieve their savegame by entering their username/password.
  2. Save-game-to-file. Players can export the savegame to XML/Json or an encrypted binary to their drive. 

I have the feeling I am not seeing the obvious solution, or am understanding something fundamentally wrong with the way itch handles updates.

Thank you in advance,

The Dynamite Whale

Admin(+1)

Games are always served from the same domain, but their path in the domain changes every time you upload a new build. This is due to how our caching system works. Do you know if it's possible to change how Unity picks the path to save the game settings to?

I think in the future it makes sense for us to have an API to store game related things on an account basis.

(Edited 1 time)

Hey,

I guess the new path is what creates this problem.

I do not know where exactly unity stores their "PlayerPrefs" but according to some posts on the unity forum #1 #2 PlayerPrefs used the IndexedDB.

I tried an alternative way by storing a JSON in unity's builtin persistentDataPath.

When I log the path to the browsers console in my test-project, the path I get is: "/idbfs/90b3e05603d8efe64ce5c035f88e6b1f"

Saving and retrieving the json fron there is no problem, but has the aforementioned issue when updating the project.


EDIT:

. In my test project I am also saving to playerprefs - and the path in the indexed DB for that, seems to be:

/idbfs/90b3e05603d8efe64ce5c035f88e6b1f/PlayerPrefs

- the JSON I save to the persistentpath ends up here: /idbfs/90b3e05603d8efe64ce5c035f88e6b1f/test.json

Other paths that unity seems to create or use:

"/idbfs/90b3e05603d8efe64ce5c035f88e6b1f/Unity""/idbfs/90b3e05603d8efe64ce5c035f88e6b1f/Unity/local.7f8d86c75cc3fab4aab80b5a6b4ef072""/idbfs/90b3e05603d8efe64ce5c035f88e6b1f/Unity/local.7f8d86c75cc3fab4aab80b5a6b4ef072/Analytics""

The persistentpath-saving I do like this (if it matters...)

C# using System.IO

        FileStream stream = File.Open(Application.persistentDataPath + "/test.json", FileMode.OpenOrCreate);          

        StreamWriter write = new StreamWriter(stream);
        write.Write(JsonUtility.ToJson(state));    
        write.Close();

I'm eager to hear if somebody finds a solution to this.