Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Clearing PlayerPrefs without causing Facebook logout?

Discussion in 'Editor & General Support' started by bluescrn, Aug 4, 2014.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Hi,

    I'm looking for a way to clear everything that doesn't contain 'com.facebook.sdk' in the key, as currently, clearing PlayerPrefs appears to be causing the player to be logged out of FB.

    (Looking at the .plist file directly, the Facebook SDK adds a couple of keys to track it's state, and it's looking like clearing PlayerPrefs causes this to be lost)

    Is there really no way to iterate through PlayerPrefs keys? - to remove them selectively?

    (The reason for clearing PlayerPrefs is that we're moving our savegame from to a separate file in our next app update. Our save has grown fairly large, so we don't want to waste memory having an unused old copy left behind)
     
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    No, there is no way to iterate over the keys. The idea is that you've created them individually, so will know what keys are stored.
     
  3. BFS-Kyle

    BFS-Kyle

    Joined:
    Jun 12, 2013
    Posts:
    882
    Why dont you try something like this:

    Code (CSharp):
    1. void ClearPlayerPrefsSafely()
    2. {
    3.     string _Key1ToKeep = PlayerPrefs.GetString("FBPassword");
    4.     int _Int1ToKeep = PlayerPrefs.GetInt("FBUserID");
    5.     PlayerPrefs.DeleteAll();
    6.     PlayerPrefs.SetString("FBPassword", _Key1ToKeep);
    7.     PlayerPrefs.SetInt("FBUserID", _Int1ToKeep);
    8.     PlayerPrefs.Save();
    9. }
     
    Graham-Dunnett likes this.
  4. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287