4

I am having a similar problem but only in one mobile SAMSUNG GALAXY S6, we are providing some default coins when player installs the game(suppose 15000). When i install the game, 14,500 coins are showing,when i checked it, playerperf has a key at the time of installing itself.I checked log but no use.No app data is present after uninstalling but the issue is occuring. Any help is welcome, Thanks in advance guys.

Fredrik Schön
  • 4,888
  • 1
  • 21
  • 32
Mohan Reddy
  • 49
  • 1
  • 7

2 Answers2

3

You can try to delete the PlayerPrefs before initializing the default coins.

PlayerPrefs.DeleteAll();

Use with caution - you can't undo that.

Emaro
  • 1,397
  • 1
  • 12
  • 21
  • Well It kind of not working for `PlayerPrefs.GetInt("Key");` because its default value is 0. – Saad Anees May 15 '19 at 08:48
  • @SaadAnees and what exaclty does not work? What do you expect from a reseted integer? – Emaro May 15 '19 at 13:30
  • I meant to say that Int value is not null or empty after deleting all PlayerPrefs – Saad Anees May 16 '19 at 10:08
  • Yeah, but it should be 0. You can't have a null value on a int (on an int?, but PlayerPrefs don't handle that). Deleting the prefs resets all integers back to zero. I think that's the expected behaviour. If you need other defaults than 0, you can set them after the call to DeleteAll. – Emaro May 16 '19 at 12:34
0

You could make some checking for example are you playing the game inside editor or on device something like this:

if(Application.isEditor)
{  // save coins with key}

else { //save coins but using different key }

Or replace PlayerPrefs with JSON.

Yupi
  • 4,402
  • 3
  • 18
  • 37