- Home /
what's the result of PlayerPrefs.Get... if the key/value was never set?
I'm wondering what the result is specifically if you try and get something from player prefs that was never set.
So like, if you did
 int x = PlayerPrefs.GetInt("ThingThatDoesntExist");
where "ThingThatDoesntExist" was never set anywhere in code
I can't find the player prefs data on my phone and thusly cant see if my variables are being created properly
Thanks for any help
Answer by tanoshimi · Dec 13, 2016 at 05:11 PM
ok, thanks, I see that obviously now after clicking the link : \
So I guess the default keys are int = 0, float = 0.0 and string = "" ? not sure where to find that info
Thanks again : )
Actually "defaultValue" is an optional parameter. Just look carefully at the signature of GetInt / GetString / ...
You usually want to pass your own defaultValue like this:
 int x = PlayerPrefs.GetInt("ThingThatDoesntExist", -1);
 if (x == -1)
 {
     Debug.Log("Not set yet");
 }
Alternatively you can check if the key exists with Has$$anonymous$$ey before you even try reading it.
Your answer
 
 
             Follow this Question
Related Questions
Saving with PlayerPrefs? How it works? 1 Answer
Saving and loading game with PlayerPrefs 1 Answer
Save Datasets at runtime 2 Answers
Store Current Level Using Preferances? 1 Answer
Converting from an Int to a Float and back with PlayerPrefs 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                