- Home /
Achievements with PlayerPrefs...
I want to make my own mini achievement system. I was just wondering if it would be valid to use PlayerPrefs to do so. Has anyone done something like this? Or should I use a text file like I read about somewhere? (This is for an iPhone App btw)
My plan is to just use an if statement to check if you achieved something and then if so save it to PlayerPrefs as true. Then in the achievements scene, check to see if the achievements are marked true and light those trophies up.
Just to clarify, I know how to code it, just wondering if this method would work well or if there is any better method.
Thanks.
Answer by getluky · Aug 04, 2011 at 09:46 PM
I would recommend writing out text files instead of using PlayerPrefs, especially as you start storing larger amounts of data. Stability was an issue for me a year ago when over-using PlayerPrefs for persistent game save data, achievements, etc. and I ended up writing a FIle IO layer that handled serialization and validation of hashtables, string arrays, etc. It worked much better, and now that Android gives you back a persistentDataPath, can work basically with the same C# code without having to delve into Java.
Could you give me some pointers on how to set my game to save and retrieve data to/from a text file? I don't have much experience there. Thanks again.
This script from Unifycommunity looks like it might help. Have a look:
http://www.unifycommunity.com/wiki/index.php?title=SimpleDictionary
hmmmm ok. I'll try this out. Also, how much do you think is too much for PlayerPrefs? If I don't get a good grasp of txt files I will probably store highscores, number of gems, and achievements (about 10). Do you think that is too much?
If there are stability bugs with PlayerPrefs, lots of people would like to know concretely. Your answer is basically "don't use PlayerPrefs for anything".
PlayerPrefs has a 1$$anonymous$$B limit on WebPlayer (not sure on iOS), so if you went over that, you would have gotten problems.
A few highscores and counts is a tiny amount (probably about 1 $$anonymous$$B in total). It will be no problem at all for PlayerPrefs.
Answer by Waz · Aug 05, 2011 at 12:29 AM
PlayerPrefs is the perfect choice for what you are doing, provided you keep below the size limit (1MB on WebPlayer, not sure on iOS). Note that this limit includes all past keys, so if you do something like:
PlayerPrefs.SetString(Time.time.ToString(),"Waste Memory");
Then you'll quickly fill it up. More concretely, if you store game save files and don't delete old save keys, you will run into problems.
thanks. How could I find a definite amount of how much PlayerPrefs space I'm using? The edit log?
@Waz im wondering the same thing, is there a way to VEIW how much space you are using at any given time, AND is there a way to FLUSH or Delete OLD keys? Do you have an example?
Your answer
![](https://koobas.hobune.stream/wayback/20220612170548im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PlayerPrefs aren't working in iphone 2 Answers
Is "PlayerPrefs" (Get/Set) slow ? 2 Answers
iphone PlayerPrefs 4 Answers
Where on iPhone editor are playerprefs stored. 1 Answer
Is there a useful upper limit to the size of ArrayPrefs (PlayerPrefs) data? 1 Answer