- Home /
Can I save a whole Dictionary?
Hello,
Can I save a whole Dictionary in PlayerPrefs? Or do I have to save each variable of my Dictionary individually?
I'm using Dictionaries to save my scores and other stuff, and I wonder if I can just save the whole dictionary or I have to create a function that save each line of the dictionary.
Thank You.
Answer by Eric5h5 · Dec 06, 2010 at 11:49 PM
You could use a technique like ArrayPrefs, where everything is concatenated into a string, and the process reversed when loading. It's faster and takes less space than having individual entries.
Answer by Statement · Dec 06, 2010 at 11:57 PM
If you want to treat your playerprefs as any stream, you might want to check out PlayerPrefsStream. You can use your old stream formatting techniques on it.
Answer by Elecman · Jan 26, 2014 at 01:46 PM
Old topic, but for reference: You can convert the dictionary to a string and save it with PlayerPrefs. Then you can take the string and convert it to a dictionary.
See here: http://www.dotnetperls.com/convert-dictionary-string
Answer by ImranZahid · Jul 10, 2014 at 08:37 AM
I usually convert Dict object into json and save as string in PlayerPrefs
Your answer
![](https://koobas.hobune.stream/wayback/20220613090035im_/https://answers.unity.com/themes/thub/images/avi.jpg)