Search Unity

Looking for Saving Recommendations

Discussion in '2D' started by Cornysam, Aug 8, 2019.

  1. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Hello everyone!

    I am just looking for suggestions/recommendations on types of saving for my game. It is a mobile platformer (so unique!) that will have short levels that are represented on a map/scene. Kind of like Angry Birds or an older Mario game where you have all of the levels showing on scene but only after you beat a level does the next one unlock. I have no problem setting this up, but was looking for ideas on saving this data so when a player closes down that they can open the game back up and it knows what levels they have beaten and what they still have left to unlock. There will be score based on time the level is completed but no items or anything like that needing to be carried over.

    I am comfortable with PlayerPrefs but wasnt sure if binary formatting or other saving techniques would be best for my simple game. Thanks for the suggestions!
     
  2. Silasi

    Silasi

    Joined:
    Jul 25, 2016
    Posts:
    48
    I don't know if this is efficient (i'm a new programmer) but I would use PlayerPrefs.
    When the level is completed, use the line
    PlayerPrefs.SetInt("LevelOne", 1)


    When the game starts next time, check if the level was completed:
    Code (CSharp):
    1. if(PlayerPrefs.GetInt("LevelOne", 0) == 1)
    2. {  
    3.     UnlockLevel();
    4. }
    If the leves was not completed, PlayerPrefs will return 0, so it will not unlock the level. If it is 1, then it will. The 0 in PlayerPrefs.GetInt is the default value.

    Please watch "Save & load system" from brackeys for you to understand it better
     
    Cornysam likes this.
  3. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Thanks Cobra. This is what i was going to default to if no one mentions a different way that may suit my needs better. I imagine that PlayerPrefs is probably the way to go but i want to make sure i am on the right path before i get started in setting up this system.
     
  4. amitbu

    amitbu

    Joined:
    May 16, 2019
    Posts:
    12
    Hey Cornysam, for you game I think PlayerPrefs will fit best, you can create a JSON tree (Of course you will have to read a bit about Unity Serialization and the attribute Serializable)
    and save all your levels inside "Levels" or whatever you want to call it, It will look something like this:
    {
    "Levels": [
    {
    "name": "Level1",
    "name": "Level2",
    and so on...
    }
    ]
    }

    and you can do everything you can do on a list.
    If you want that the data will be saved even after the user reinstalls the game, you'll have to use a backend service, like Firebase, GameSparks, Playfab and a lot of others.
     
    Last edited: Aug 8, 2019
    Cornysam likes this.
  5. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
  6. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    I kindof like binary files personnally. You can make a class that holds lists<leveldata> for example. Leveldata would be a struct holding the score of the player in an int, a bool to know if the level was passed,and an id as uint refering to which level it is. Create a method that serialize those and a method to deserialize it. Then in your class holding the list, make it write the amount of leveldata it contains,then write every of those data one by one. To read it, read first the amount of leveldata , then read one by one those and add it to the list.
     
  7. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    (Sorry for the double post but mobiles and edit function dont work well together).
    Binary files are smaller than json/xml/yaml but are a bit more difficult to handle (not that much) and are harder to modify manually. They are better if you need to send them over the internet.
    PlayerPrefs shouldnt be used to store saves, they are better when it comes to store stuffs like resolution settings, prefered folders for things like where to save the save files, and other things that are linked to the computer that is used.
     
    Cornysam likes this.