I am making a project on Unity for WebGL but the code that I wrote for saving and loading from a file on PC seems to not work on WebGL. Does anybody know how to save on WebGL? The project has quite a bit of variables so I would prefer to avoid using PlayerPrefs.
This is the code that I tried to use for saving and loading
You can save the Json into PlayerPrefs as a string but I would at least format it to its minimal format, or better yet, use a binary serialization of either the json or the data in question.
All other solutions involve either platform-specific code (save/open file dialog - windows-specific, may not work in every browser and is annoying for users and there is no guarantee user will do the right thing) or a remote server/database to set/get the data (requires at a minimum a unique user ID that is somehow generated, or better, a user account/login).
There is no file system access in WebGL. It’s all in a sandbox. You cannot read or write specific files that will show up in File Explorer. If you save in webgl you have to load in webgl and confirm that the values are identical.
Like the docs says anything you try to save as a file is sent into idbfs/<md5 hash of data path>. An idbfs is just a database pretending to be a file system.
The <md5 hash of data path> can be scrambled with new builds too which can lead to being unable to find the data that was associated with a previous build. The link below has a workaround for this.
Thank you very much for your help. After looking at multiple solutions, I have decided to pick the most simple one, which is to turn the save into a string and show it to the player so they can copy it locally. Perhaps not the best solution but my game is simple enough to allow that.