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.

Read the docs :wink:

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

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

Registry element size limits - Win32 apps | Microsoft Learn

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.”