Hi, what does PlayerPrefs.Save() do ? I’m asking this because I just use PlayerPrefs.SetInt() and PlayerPrefs.GetInt() and my game saves perfectly. Why should I use PlayerPrefs.Save() ?
Thanks in advance.
Hi, what does PlayerPrefs.Save() do ? I’m asking this because I just use PlayerPrefs.SetInt() and PlayerPrefs.GetInt() and my game saves perfectly. Why should I use PlayerPrefs.Save() ?
Thanks in advance.
Im quoting the documentation
“By default Unity writes preferences to disk on Application Quit. In case when the game crashes or otherwise prematuraly exits, you might want to write the PlayerPrefs at sensible ‘checkpoints’ in your game. This function will write to disk potentially causing a small hiccup, therefore it is not recommended to call during actual gameplay.”
In other words it just only for security. Of corse it is not really acceptable if the game crashes but if it does better safe than sorry. So it is recommended to write it to the disk at certain points like pause,scene change, loading etc…
PlayerPrefs keeps two copies of its data:
You can make as many changes as you want, but you’ll want to periodically call Save to make sure those changes aren’t lost in a crash.
Some people call Save
after every change. That’s fine, if you don’t have a lot of data.
Other people call Save
each time they switch scenes, or at some other sort of reasonable checkpoint.
The docs are saying Save
should be called automatically when your application exits. That’s new to me, and I’m guessing it was added recently. Possibly in Unity 4.3