- Home /
PlayerPrefs Lmitations
Hey there everyone, I was just wondering how big PlayerPrefs can be for my using, and the maximum amount of variables I can store into it. Perhaps just an example of it's limitations?
I'm curious because I plan on having it check for a lot of things - presumably over 50 - for level items, character stats, etc. and I guess I'm just a little cautious on how to spare them.
Are they the only way to retain Game states and what not? And should I be okay with using them like crazy, or will they be a little too cost effective by doing so?
Thanks for anyone willing to lend a hand, Jordan.
Answer by Tseng · Nov 04, 2011 at 02:59 AM
Read the docs ;)
http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html
Basically there are no hard limits, with exception of WebPlayer, which is limited to a 1 MB.
edit: To the second part of your question: No they are not the only way, but the easiest.
You usually use them to store preferences, settings, highscores. If you want to save a level's current state, you better write your own Serialization/Deserialization Methods. But that's a bigger topic, so just google for "Serialization C#" for tutorials and explainations
Thanks! Now is there any benefits to using the Serialization/Deserialization methods oppose to just doing the stats and such in PlayerPrefs?
how about working with iphone / android? it doesn't seem to work at all! http://answers.unity3d.com/questions/139856/iphone-playerprefs.html
i would just like to share with you an asset i came accross a while ago by a regualr answerer DontDoIt (i think) its a save component which makes saving really easy and its free, i havent used it yet but the videos ive seen makes saving a simple click of a button
actually it whydoidoit http://forum.unity3d.com/threads/138678-Unity-Save-Game-Level-Serialization
i was just reading up on player pref performance or speed and came accross a forum which said over 300 will be a bit slow on ios and android however this is from last year heres their solution
http://www.previewlabs.com/writing-playerprefs-fast/
heres the page i found it on as well
http://answers.unity3d.com/questions/17873/saveload-playerprefs.html
Answer by sonnyb · May 29, 2019 at 04:27 PM
There is a size limit that depends on the platform. (WebPlayer is not the only exception.)
See the answer by guavaman in this post
The size limit will depend on the platform. For example, on Windows standalone builds, PlayerPrefs uses the registry to store the values. According to Microsoft, the length limit of a registry value is 1MB. Registry Element Size Limits
So there is no fixed size limit set by Unity. You'd have to do testing to determine what the limit is on each platform.
And see the comment by MikeNewell in this post:
Player prefs are stored in the registry on Windows and the max size of a registry value if 1mb
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724872(v=vs.85).aspx
On mac they're stored in a property list but I dont know much about them...
The web player stores player prefs as a binary file, but there is a 1mb limit to their file size.
Additional details:
The Registry Element Size Limits page states the registry value size limit: "Available memory (latest format) 1 MB (standard format)"... According to a comment by Alex K. in this SO post: "Standard Format is only Win2k - except for HKCU which is always in this format on all versions of Windows. ". Also note that the docs also say: "Long values (more than 2,048 bytes) should be stored in a file, and the location of the file should be stored in the registry. This helps the registry perform efficiently."
Your answer
Follow this Question
Related Questions
Need experienced opinion: Saving a players inventory: XML or PlayerPrefs? 1 Answer
I cannot store data into PlayerPrefs after a certain amount of data 2 Answers
Need help with using Player Prefs to save number of coins collected. 1 Answer
Combine items in inventory (a la LucasArts) 0 Answers
Saving Scenes and loading GameObjects? 4 Answers