A
A
Alexander Pianov2020-05-15 19:13:40
C++ / C#
Alexander Pianov, 2020-05-15 19:13:40

Why are PlayerPrefs reset after the second run?

After many uses of PlayerPrefs to save user profile data, I ran into a problem.
There is a button to save the hairstyle selection:

PlayerPrefs.SetString("pickedHairName", "Hair1");
Debug.Log("Save Hair success");

It is loaded successfully from PlayerPrefs on first start.
private void Start()
    {
        if (PlayerPrefs.HasKey("pickedHairName"))
            pickedHairName = PlayerPrefs.GetString("pickedHairName");
        else
            pickedHairName = "bold";

On first run "pickedHairName" equals "Hair1", the character gets hair.
However, on the second run, "pickedHairName" is already "bold", the unfortunate character loses his hair.

At the same time, nothing overwrites it, there is no repeated Save Hair success log, and PlayerPrefs.DeleteAll is not used anywhere.
What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mopsicus, 2020-05-15
@mopsicus

PlayerPrefs.Save being called after the variable has been written?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question