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.

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”);

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…

I had to do a workaround, by saving and loading it as something else, so it didn’t get reset after the restart.

@ExtremePowers can you help me with te code written for setting and saving the quality settings