Search Unity

PlayerPrefs doesn't work from Play Store install, but does from editor/APK?

Discussion in 'Getting Started' started by TinyHappySteps, Aug 2, 2017.

  1. TinyHappySteps

    TinyHappySteps

    Joined:
    Aug 2, 2017
    Posts:
    2
    Help, PlayerPrefs doesn't seem to work and can't figure out why.

    I have a simple game that starts with:

    void Start()
    {

    if (PlayerPrefs.GetInt("IsReturningUser") == 1)
    {
    ScoreLabel.text = "Welcome back, friend!";
    }
    else
    {
    PlayerPrefs.SetInt("IsReturningUser", 1);
    ScoreLabel.text = "Welcome new player";
    }
    When testing on my Android device from Unity Editor (build and run while connected) it works as intended - when I return to app second time it detects I'm returning.

    However when I published the same code to Google Play store and clean installed from there, it never detects I'm a returning user when I return to app the second time.

    Also strange, while it doesn't work on my Android phone, on my wife's phone installed from the Play Store it does detect as a returning user when she opens it the second time.

    Any ideas?

    Unity 5.3.6 My phone - Redmi Note 3, Android 6.0.1 MIUI 8.2 Stable Wife phone - OnePlusX
     
  2. TinyHappySteps

    TinyHappySteps

    Joined:
    Aug 2, 2017
    Posts:
    2
    Answering my own question - turns out player prefs only saved when an exit procedure is triggered, but on my phone I was force closing it which I guess skips that. Solution was to write it manually each time values changed.