Player prefs don't save on Android but do in game editor

I seem to be having an issue with my player prefs for Android. Take a look at my script.

void Start () {
        igPoints = PlayerPrefs.GetInt ("Score");
    }

So first I have it make this PlayerPrefs Score int display as my integer igPoints.

void OnApplicationQuit(){
        PlayerPrefs.SetInt ("Score", igPoints);
        print ("Quit"); // <--- This works
    }

Then this should save the “Score” in PlayerPrefs when quitting/closing out of the app… what did I do wrong? It’s probably a simple mistake or misunderstanding but eh, I haven’t requested help since July of 2016 so, I’m getting better at this whole thing.
EDIT: My end result I have not found the issue but instead I will just call the save whenever the player receives points/spends them.

Try calling PlayerPrefs.Save() right before your print “quit” statement, after the SetInt in other words… You shouldn’t HAVE to do that, but if it fixes your problem, a) your problem is fixed, and b) you can file a bug with unity!

To test if the issue is saving, I would do a call elsewhere and see if it’s working at all for you or just not working in the OnApplicationQuit method.

1 Like

Woah, you are right. I called it in it’s own function when clicking a button and it saved… any help on how to get it to work on exit?

Why not simply put the save the same place where you call Application.Quit?

The save isn’t required inside a quit function if you have a set int, it’s implied. ~ Unity Docs
This is NOT the issue I am having, regardless and yes I have tried adding a save into it anyway.

I guess it’s bad phrasing on my part, i meant putting the PlayerPrefs.SetInt in the same place where you call Application.Quit, reason being this i believe guarantees the applying of the new value in the PlayerPrefs happens before the application quits.