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

Serializable PlayerPrefs

Discussion in 'Scripting' started by natmaxex, Oct 15, 2021.

  1. natmaxex

    natmaxex

    Joined:
    Jul 12, 2012
    Posts:
    68
    Dont bite my head off, I'll keep it simple, you don't even need to tell me how.

    Can you Serializable PlayerPrefs like this. "I just want to know if it's posable"
    Disclaimer: In the Example below is being done with XML.
    I want to know if it can be done with PlayerPrefs IDK what to tell you.
    I know you want everything to be perfect but if i had PlayerPrefs code that did this i wouldn't be making this post so i don't know what you want from me.
    Code (CSharp):
    1. [System.Serializable]
    2. public class XmlTestData
    3. {
    4.     public string testString;
    5.     public bool testBool;
    6.     public int testInt;
    7.     public float testFloat;
    8. }
    Full code Here
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    I wouldn't recommend to put XML in
    PlayerPrefs
    , on Windows it gets written inside the registry. You can write
    int
    ,
    float
    and
    string
    . If you write
    bool
    as an
    int
    , you can store all of your data from this class into
    PlayerPrefs
    .
    https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
    I also don't recommend to store extensive data in there, only small amount config. Like score, keyboard layout, etc.
    If you have a lot of data, write it into a file in the
    Application.persistentDataPath
    .
     
    natmaxex likes this.
  3. natmaxex

    natmaxex

    Joined:
    Jul 12, 2012
    Posts:
    68
    Thank you for the documentation, very helpful. I'm looking into it now. :)

    Just to clear thing up I know XML doesn't go into PlayerPrefs I just wanted to know if I could use the same methods using PlayerPrefs
    Code (CSharp):
    1. [System.Serializable]
    2. public class PlayerPrefs
    3. {
    4.     public string testString;
    5.     public bool testBool;
    6.     public int testInt;
    7.     public float testFloat;
    8. }
    You answered the question no it cant.:)
     
    Last edited: Oct 15, 2021