Y
Y
yraiv2020-01-03 09:24:07
Unity
yraiv, 2020-01-03 09:24:07

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

3 answer(s)
F
freeExec, 2020-01-03
@yraiv

Application.Quit- there is nothing else. Well, then you can delete it when you open it.

G
GavriKos, 2020-01-03
@GavriKos

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

G
GFX Data, 2020-01-03
@ShockWave2048

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 question

Ask a Question

731 491 924 answers to any question