- Home /
Max size for PlayerPrefs.GetString or SetString ?
Is there a maximum length for the String you can store to PlayerPrefs?
Answer by scone · Apr 28, 2013 at 09:48 PM
So, I actually went and tested this. I found that in the editor, and in Windows builds, this breaks at a 1MB string. Oddly enough, on Android, it juts goes up till it crashes, but then every time I try to run it again, it crashes immediately.
using UnityEngine; using System.Collections;
public class PPDump : MonoBehaviour {
public int length;
public string original = "x";
string str;
public int count;
public bool run;
void Start() {
count = 0;
length = 0;
str = original;
}
void OnGUI() {
GUILayout.Label("Length: " + length);
}
void Update () {
if(run) {
str += str;
length += str.Length;
PlayerPrefs.SetString("save " + count, str);
if(PlayerPrefs.GetString("save " + count) != str) {
Debug.Log("Broken");
run = false;
}
count++;
}
}
}
Answer by guavaman · Jul 28, 2014 at 01:13 AM
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.
FYI, Windows also has another little quirk when storing data in the registry. If your value name length (what Unity calls a key) is 255 characters or longer, the value will not show up in Regedit, though Unity will still load the value fine. Unity appends a 12 character suffix to whatever you name your key, so the max chars you can use without making the value invisible to Regedit is 243 characters.
Answer by _Petroz · Nov 02, 2011 at 02:26 AM
I don't think there is a maximum size per element but there is a maximum size for the total data (the smallest is webplayer which is 1MB).
http://answers.unity3d.com/questions/151948/how-many-variables-can-i-store-using-playerprefs.html
The 1$$anonymous$$B limit does only exist in the webplayer. In standalone builds the playerprefs are stored in the windows-registry or as a seperate file on $$anonymous$$ac OS. For more information read the PlayerPrefs docs.
I thought the 1$$anonymous$$B limit might be specific to one platform, thanks for clearing that up.
How do you try finding out the definitive max string size for mobile platforms
I am informed that there is no limit (except for device memory) on mobile - Web is limited to 1$$anonymous$$B total size.
Your answer
Follow this Question
Related Questions
PlayerPrefs for saving strings 1 Answer
PlayerPrefs script problem 2 Answers
How to convert raw keycode to characters 1 Answer
PlayerPrefs from One App to Another. 1 Answer
PlayerPrefs Question 0 Answers