- Home /
Save Quality settings
How to save which quality setting the player has chosen using PlayerPrefs, my idea of this would lead to something like this:
PlayerPrefs.SetInt("UnityGraphicsQuality", QLevel);
Where QLevel is a number that changes when the player clickes a button, but this seems to get reset everytime the game restarts. NOTE: I have disabled the start up menu, because I wanted it to be in-game only.
So, before restart I run this code: QLevel Starts as 3, then the player changes QLevel to be 5.
PlayerPrefs.SetInt("UnityGraphicsQuality", QLevel);
PlayerPrefs.Save();
Then after a restart I run this code:
var QLevel = PlayerPrefs.GetInt("UnityGraphicsQuality");
QualitySettings.SetQualityLevel (QLevel, true);
After the restart if I Debug.Log QLevel it is 3, so the value got reset on startup. I have checked in the registry and the value becomes 5 untill I restart the game, then it is back to 3.
Answer by Ouss · Dec 06, 2014 at 08:52 PM
You save QLevel in player prefs, but where do you load it so you can get the previous value ? you should have a variable retrieving the value saved in the player prefs: PlayerPrefs.GetInt("UnityGraphicQuality");
That is what i am doing, sorry for not making it clear. The problem is that everytime i launch the game the value is the same Quality number 3 and if i check in the registry it has also been changed to that value.
Answer by SquigglyFrog · Dec 07, 2014 at 12:26 AM
You might be setting it to some initial value every time you run it, before you load.. You can do something like this:
if(playerprefs.haskey("UnityGraphicsQuality")
{
qLevel = playerprefs.getint("UnityGraphicsQuality");
}
else
{
playerprefs.setint("UnityGraphicsQuality", 3);
qLevel = 3;
}
This way if it IS set it just reads it in, if its not it sets it..
Okay, 1. I set the value using olayerprefs and when i check in the registry it is changed. 2. I restart the game, and the value gets redet to wha it was before the value was set. 3. when i get the value it is giving me 3 after a restart. All in all, the value gets saves but after a restart is isn't saved.
Answer by ExtremePowers · Dec 23, 2014 at 10:31 PM
I had to do a workaround, by saving and loading it as something else, so it didn't get reset after the restart.
Answer by saviom80 · Feb 12, 2018 at 12:02 PM
@ExtremePowers can you help me with te code written for setting and saving the quality settings
Your answer
Follow this Question
Related Questions
PlayerPrefs Bug 0 Answers
How do I save a three dimensional array? 1 Answer
How to save an Audio Mixer's value wich is adjusted with a Slider? 1 Answer
Save/load playerprefs 2 Answers
Problems with saving/loading score with PlayerPrefs [C#] 1 Answer