- Home /
Differences between mobile save/load data
Dear Community,
I'm trying to figure out how to save 3 values permanently for a mobild game (android). Means when the player close the APK and open it again, the values will not be restarted to default or get deleted. A simple Save and Load function.
The 3 values are: a string with the name of the player, an int for HighScore and a bool for asking if you have already played a tutorial level need to be saved and loaded.
I am a beginner and try to code it in C# in Unity 5.6.2 .
However, my question is how do I save these values best? I have found that there are 3 possibilities.
save with Custom BinaryFile
Save with XML files
Save with PlayerPrefs
Which of these would be the best way to save these 3 values?
Answer by MaxGuernseyIII · Sep 26, 2017 at 05:43 PM
This might really be a forum post, since you are seeking opinions rather than a conclusive answer. I mean, I'm sure you want a conclusive answer but there isn't one, really.
PlayerPrefs is cheap to implement but it also is (or at least was) not a safe place for save and load. I've been burnt a number of times with my first game.
XML files or JSON files (which are en vogue, right now) are a little more flexible than a binary file probably will be. If you write your own code to format and unformat the save-file, you have complete control and, if you change your design, you can modify your formatter/unformatter as required.
I don't know what you mean by "custom" binary. Do you mean you define a binary format and then write something that serializes and deserializes state as appropriate? That's basically a more-terse and more-rigid way of doing what you would do with XML or JSON. Smaller saves, a little harder to hack, but it's a little easier for things to go wrong.
If by "custom binary" you meant using any built-in serialization technology, you are trading implementation cost now for coupling later. Once you have data in the wild that is inextricably linked with a portion of your design, changing those design details becomes impractical.
Generally speaking, I go for either XML or JSON, written and read by a custom formatter, and then compressed. I compress it because it makes it ever-so-slightly more difficult to cheat. It's a marginal increase in difficulty but it makes me feel good.
Thank you for your answer. I didn't know that I put that question into wrong forum.
Now I know that I should search for some X$$anonymous$$L or JSON code tutorials to save my values. How I say, I didn't know where to start.
Your answer
Follow this Question
Related Questions
How to create log by PlayerPrefs? 1 Answer
Saving data 1 Answer
Using XML files and playerprefs together 0 Answers
PlayerPrefs to save setActive state 2 Answers