2
\$\begingroup\$

PlayerPrefs are easy to implement and i think it can be used to store important game data like selected character and coins and completed quests for small games, but i have read too much to make me ask this question that why not use it, and what is the other options for storing important game data in

\$\endgroup\$
  • 1
    \$\begingroup\$ Can you provide source of where you read that? The general advice is if it works for you, then there's no reason not to use it. \$\endgroup\$ – TomTsagk Aug 6 at 8:10
  • \$\begingroup\$ You can find this topic discussed previously on this site here and here, among other examples. \$\endgroup\$ – DMGregory Aug 6 at 11:12
8
\$\begingroup\$

As implied by the name, PlayerPrefs is mostly intended for storing config options. But it can also be abused to store savegame data, if that data is rather small. If you target platforms without write-access to a filesystem (like WebGL) then it might in fact be your only option to persist data without relying on external online services.

However, if your game data gets larger, then you soon hit some limitations:

  • Some of the platform-dependent methods it uses to store data are not designed to hold large amounts of data (like the Windows registry)
  • There is no elegant way to store binary data or arrays. You either have to encode them as strings, or store a bunch of uniquely named Float or Int values (and in that case the keys will take up more space than the values, so it will be very inefficient).
  • PlayerPref's loading and saving is all-or-nothing. You can not load a single savegame, you have to load them all.
  • It is difficult for players to exchange savegames as files, especially between different platforms.

So if you plan to add savegames to your game and the game state which needs to be saved is more than just a hand full of numbers, then you might want to consider to create real savegame files on the filesystem in a format of your design which you read and write with the standard .NET classes for file access.


Also, if you have something which the player must not be allowed to modify (like ingame items bought through microtransactions or player progression in a multiplayer game), then you generally don't want to store those on the end-user device at all. In that case you won't get around setting up an online service which manages that data.

\$\endgroup\$
  • 5
    \$\begingroup\$ One other reason to add is that PlayerPrefs can be reset by things like a system rollback point on Windows, which is probably OK for your options settings that you can just put back the way you like them, but less OK for hours of gameplay progress. Your point on copying/exchanging save games also applies to creating backups too. \$\endgroup\$ – DMGregory Aug 6 at 11:00
0
\$\begingroup\$

Another thing is that Player Prefs can be easily hacked, so if you don't want a gamer to hack into them and unlock an awesome character, you should avoid using it for that kind of memory.

\$\endgroup\$
  • \$\begingroup\$ This is already covered by Philipp's answer ("Also, if you have something which the player must not be allowed to modify (like ingame items bought through microtransactions or player progression in a multiplayer game)"). This kind of hacking can be achieved even if you use another type of savegame. \$\endgroup\$ – Alexandre Vaillancourt Aug 7 at 2:35
  • \$\begingroup\$ Any data stored on the user's hardware can be more or less easily hacked. \$\endgroup\$ – Philipp Aug 7 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.