In Unity, I have an InputField calling this method for OnValueChanged:

public void SetUsername (string s) {
    username = s;
    PlayerPrefs.SetString ("username", s);

print(s); succesfully prints the typed text, but PlayerPrefs.SetString ("username", s); is saving what looks like garbage data. After exiting the game, here's what the relevant line of the PlayerPrefs file looks like:

<pref name="username" type="string">ZHNmc2Rmc2FkZg==</pref>

ZHNmc2Rmc2FkZg== isn't the string I saved...

What's going on? What am I doing wrong?


1 Answer 1


This happens because Unity does not directly write the string to the PlayerPrefs file, instead, it serializes it into a format which can be saved without conflicting with the XML. For example, it would be bad if you tried to save the string </pref>.

This string will appear correctly once loaded with PlayerPrefs.GetString().

I figured this out while writing the question. I hope others can find this useful.

  • \$\begingroup\$ Nice information to have, thanks for sharing this. \$\endgroup\$ Nov 16, 2017 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .