Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

PlayerPrefs not saving

Discussion in 'Windows' started by plasticYoda, Oct 16, 2013.

  1. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    In the process of moving an iOS title to Windows Store - every time I run the build via VS2012, or by clicking on the icon in Start the saved playerprefs are reset.

    I'm def. calling .Save() when I make changes, but nothing seems to stick. I'm sure it's something simple, but I've no idea what.

    Any clues?

    Thanks,

    PY
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,948
    PlayerPrefs for Windows Store Apps are saved here - C:\Users\<user>\AppData\Local\Packages\<your app name>

    I think whenever you change something in your project, and VS has to rebuilt it, it will delete that folder, thus clearing player prefs.

    This shouldn't be happening, are you sure you're calling - PlayerPrefs.Save ?

    Also there was a bug in 4.2 I think, that PlayerPrefs were loaded after OnEnable function, meaning they're only available in Start or later function. Maybe you're seeing this problem.
     
  3. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    Calling the Save method after a change.

    Using the latest 4.2.2 Unity build VS2012 -- I'll investigate the folder and see if they are showing up.
     
  4. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    So, the file shows up and from some quick testing, it seems that you are right - I can't load prefs before a Start function - which is a bit of a shame - I'll have to try moving things around and see what can be done.
     
  5. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    Ok, confirmed - I moved my LoadPrefs call to a Start function on a script with high-priority and had it then call my old Awake code to set everything up. This read the prefs file in correctly. Looks like that issue is still in 4.2.2.

    Thanks for the help.

    PY