2
\$\begingroup\$

I'm building a mobile game for a client in Unity. To save time, we started with a template game from the Asset Store that had some of the features that the client wants.

The game includes a progression system and shop, so we save the user's scores, progress, in-game currency, inventory, etc. We currently have no plans to export the save data.

The template game uses PlayerPrefs to store all save data. Is this bad practice? Assuming we don't include a button that calls PlayerPrefs.DeleteAll(), is there any extra risk associated with using PlayerPrefs instead of external files to store the player's data?

\$\endgroup\$
1
\$\begingroup\$

It is up to you, but on android at least it is very easy to reset these things on your phone. Most of the time it is best to save things that you do not want to lose externally so that the user cannot manipulate or delete it. I am not positive how easy it is to do on iOS, but on android all you have to do is go to the app in the application manager and clear the cache and it will remove all of those PlayerPrefs.

Overally it would not be a good option for things you need to hold on to. Especially things like in game currency as users can find ways to manipulate this data.

\$\endgroup\$
  • \$\begingroup\$ Thanks! The bit about clearing the cache on Android is very important to know. \$\endgroup\$ – user45623 Jun 27 '16 at 18:19
2
\$\begingroup\$

Yes, because PlayerPrefs are VERY unsecure. If you get into the habit of using PlayerPrefs to store data, even for games where it doesn't matter, then you'll run the risk of doing it when it does matter, such as with an online multiplayer game or some such game where cheating would make a big difference.

The reason it matters is because they are extremely easy to edit, due to them being pretty much plain text and not encrypted in any way, so the values can be directly edited.

If you want to keep your data, especially save data and everything safe, then serializing your data is the best way. You can create a function by which you save your data to a binary file, but Unity does have built-in tech for serializing data.

http://blogs.unity3d.com/2014/06/24/serialization-in-unity/

That link will tell you how Unity's own serialization works. It's not the best method or the easiest to use, but it does mean you don't have to go away and spend several hours/days making your own methods. The best approach is to make a centralised class that keeps track of all of the data at the same time. This makes serializing it a LOT easier.

\$\endgroup\$
2
\$\begingroup\$

I had issues with PlayerPrefs() on Tizen device. Same game Worked great on Android and iOS.

It's good practice using XmlSerializer or Binary Serialization. They have better control when dealing with lots of data like in your case.

\$\endgroup\$

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.