- Home /
Load Playerprefs on startup
How do I load in the PlayerPrefs at the very beginning when the game loads? Ie the player choose their UI preferences and when they load the game again it brings it back with those UI preferences rather than the default.
Answer by chelnok · Nov 19, 2012 at 06:33 AM
It is not automatic. You need to first set all things you need for later use like:
PlayerPrefs.SetInt("Player Score", 10);
When you need something, you get it:
score = PlayerPrefs.GetInt("Player Score");
Then use it:
playerScoreUI = score.toString;
More info: http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html
I understand all that. I am asking how I load the values I stored. Is there not another method aside from using Awake() on my scripts?
IE to load the values and assign when the game first starts up.
score = PlayerPrefs.GetInt("Player Score"); <- that is how your load the stored value, you can do it in awake, start, update.. wherever you like. This is pretty much all you do with PlayerPrefs.. Perhaps you need somekind of registry for your game, to keep everything in one place?
Answer by joachimbose48 · Mar 31, 2021 at 12:37 PM
I believe this might be what you are looking for. (for people searching this answer) https://docs.unity3d.com/Manual/RunningEditorCodeOnLaunch.html
Your answer
Follow this Question
Related Questions
Checking if int is !null not working ? Strange... 2 Answers
Resources.LoadAll Issue with variable type 1 Answer
How to make slider load variable on start 1 Answer
Setting variable as type "Scene" 4 Answers
Load Custom Scene 2 Answers