Answer the question
In order to leave comments, you need to log in
How to implement data reset in PlayerPrefs?
I need to reset the PlayerPrefs when the application closes, but how can I track any closings? through close everything, if you just exited through the button or brushed off the application, application crashes. Which team can track everything completely?
Answer the question
In order to leave comments, you need to log in
Application.Quit
- there is nothing else. Well, then you can delete it when you open it.
What an awesome example of an XYZ error. You don't need all of this at all - simply because it's a bad use of PlayerPrefs. Prefs are needed just to store information BETWEEN launches. Those. they just need to be SAVE at the exit \ minimize \ save points, and at the start of the game - LOAD. This is the save game.
And within the framework of a running game, it is enough to keep everything in memory
PlayerPrefs is designed to do the opposite, keep the data, not reset it.
If you need to reset on deactivation/exit, you can do the same at startup.
void Start()
{
Application.quitting += () => { OnClear(false); };
Application.focusChanged += OnClear;
}
void OnClear(bool b=false)
{
PlayerPrefs.DeleteAll();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question