2
\$\begingroup\$

I am in the process of designing a save system for a game. I would like to save to a file and upload this file online so that it can be securely accessed via login from any computer. This works fine for a desktop build but I would also like to have a webgl build accessible online so players can play the game without needing to install the desktop version. However webgl does not support a file based system for saving/loading and uses playerprefs instead.

I am trying to work out if there is a way that these two builds can coexist so that if one build is played the progress will be saved and picked up when continuing in the other build. At the same time though playerprefs obviously has a limit to what it can store which is much less than the save file so I am wondering how this would work and what should be saved and loaded and what shouldn't?

\$\endgroup\$
1
  • \$\begingroup\$ It is not correct that you have to use PlayerPrefs to store save data on WebGL (you should never put save data into PlayerPrefs). You can save/load files to/from Application.persistentDataPath using the same code as you would on desktops, and they will be stored in the browser's IndexedDB database. However, this is a local solution - the save file can only be accessed from that browser on that computer - and isn't a substitute for cloud saves. \$\endgroup\$
    – Kevin
    Mar 16, 2022 at 19:26

1 Answer 1

1
\$\begingroup\$

You could implement "Cloud Saves". Upload the savegames to an online webservice. You can access a webservice from Unity via the class UnityWebRequest. There are countless technology options for implementing a webservice on the server-side, and which one to use depends on personal requirements, preferences and skills. So I will leave this choice to the reader.

In order to permit the player to access the same savegames from multiple devices and web browser, you need to give them personalized account with username and password.

This also gives you the advantage that all the savegames on your own server give you lots of information about how your players play the game, which you can data-mine to find out if your game works the way you intended. But it also means that you need to have a privacy policy and might need player consent for analyzing their savegame data (just storing the savegame data for the user and never looking at it seems to me to fall under "legitimate interest" and thus would not require explicit consent, but IANAL).

Unfortunately, this means that you are now responsible for keeping that savegame webservice running indefinitely, or the game becomes unable to save which could render it unplayable. So in order to still keep the game playable when the server is offline, you might still want to use PlayerPrefs as the primary source of truth and synchronize the data stored in PlayerPrefs via webservices when possible.

\$\endgroup\$
5
  • \$\begingroup\$ Pardon my ignorance, but how is using a UnityWebRequest different to using a saved file? Would it work with webgl? \$\endgroup\$
    – FrontEnd
    Mar 15, 2022 at 9:54
  • \$\begingroup\$ @FrontEnd As far as I know, UnityWebRequest works with all platforms. It is used to send data to a server or retrieve data from a server. Both via the http protocol. What the server does with the data it receives, and how it procures the data it sends, is up to the server. \$\endgroup\$
    – Philipp
    Mar 15, 2022 at 9:57
  • \$\begingroup\$ @FrontEnd When you save the game on the user's local machine, this is done using a file. When you save the game to a web service, the save data is often written into a database rather than an individual file. \$\endgroup\$
    – Kevin
    Mar 15, 2022 at 19:52
  • \$\begingroup\$ @Kevin Sorry I'm confused, if data is being saved to a database wouldn't it be saved as data not a file eg. rows in a MySQL table? Wouldn't this then be the cloud save? Where as a save file would just be a file with the save data in it (possibly encrypted etc) saved and loaded to the server? \$\endgroup\$
    – FrontEnd
    Mar 18, 2022 at 9:45
  • \$\begingroup\$ @FrontEnd More or less. I was answering your question "How is using a UnityWebRequest different to using a save file"? Cloud saves could use either files or a database. You would use a web request to send the save data to the server. \$\endgroup\$
    – Kevin
    Apr 5, 2022 at 1:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .