- Home /
problem with PlayerPrefs.SetString...
Hello Unityrs,
I build a chat line.. and to log in I fill up a textArea saving the value (the username) into a variable, let's call it playerNameInput.
For example: playerNameInput = GUI.TextArea (Rect (horzOffset+30, 80, 300 , 20), playerNameInput);
Just after that statement I call:
PlayerPrefs.SetString("playerName", playerNameInput); //Setting the player's name.
But somehow, when I display the content of "playerName" field in the chat room, I get always the previous one and never the current. So, I wonder when the PlayerPrefs are saved?! and How can I update PlayerPrefs at runtime.
Many thanks. Giancarlo
Answer by AliAzin · Aug 18, 2010 at 02:10 PM
You should use
PlayerPrefs.GetString("playerName");
in order to read those data.
I know, I did it but somehow, it seems that the PlayerPrefs get saved as soon as the session finished as every time I connect it back, I always get back the previous PlayerName and not the current one.
Answer by BloodFox__88 · May 23, 2013 at 09:41 AM
In order to save the preference you must use:
PlayerPrefs.Save
unity automatically saves upon application quit/ exit, this is why it is always showing the previous sessions names. look here
for more info.
Eight and a half years later, this saved me. I've been trying to debug this for 2 days! Thank you!!!!
Your answer
Follow this Question
Related Questions
do player preferences get deleted if an iphone app is updated 1 Answer
Updating ui not working in fixed update .But it works in update 1 Answer
Boolean Trouble, Please help....Boolean does not flip another boolean 0 Answers
GUI.TextField problem, won't update var. 0 Answers
Score not updating... 1 Answer