Search Unity

how does PlayerPref "save" work?

Discussion in 'Scripting' started by Alex Cruba, Dec 23, 2012.

  1. Alex Cruba

    Alex Cruba

    Joined:
    Aug 16, 2011
    Posts:
    564
    I was able to store my first data 10 minutes ago and I'm glad I solved this "frightening" thing. For me it was a scary thing.

    Now I read about the "save" command: Writes all modified preferences to disk.

    Ummm... What does that mean exactly?

    1) Does it save all stored values in one?
    2) Which way I call up that command?
    3) Is it watching all values permanently if they change?
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I think, since PlayerPrefs is in itself a class, Save() will save all PlayerPrefs, regardless of script. That being said, I Save() at convenient points in various scripts. By convenient I mean, where not much action is happening on the engine.


    1) yes, not 100%, but it would make sense that one PlayerPrefs.Save(); will save any PlayerPrefs value in the project.

    2) ex. HiScore = PlayerPrefs.GetFloat("hiScore");

    3) no. PlayerPrefs is not observing anything. You set a value, save a value and retrieve a value. That's it.
     
  3. Alex Cruba

    Alex Cruba

    Joined:
    Aug 16, 2011
    Posts:
    564
    Thank You to Canada ;)
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697