Search Unity

Saving a lot of player data

Discussion in 'Scripting' started by BubyMB, Jan 2, 2019.

  1. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Hey guys, was just wondering how everyone else handles saving large amounts of player data. Thing such as exp, position and such are quite simple, but how do you guys handle things such as current quests, progress through a quest and things more complicated. I have a general idea of how I want to save it, but I feel like it would take a lot of time to read. (I am using a binary decoder)
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,645
    Basically you have two viable ways:

    - you serialize the objects you want to save
    - you go through one by one and save the data as you wish by hand

    The first one simpler but you will save a lot of junk data, which you don't need, the second one is more precise, but you really need to think through what do you want to save and so on. I personally work on the second one.
    You can get a glimpse here regarding the second option: https://catlikecoding.com/unity/tutorials/hex-map/part-12/
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,847
    I like @Lurking-Ninja 's hex tile example that he linked, but with one exception: personally I would not use binary serialization. I take his point about data size, but in terms of debugging, binary file storage just makes for an extra hurdle.

    Instead, use something like JSON or XML so you can see what you're saving just by pulling it up in a text editor. You are going to have bugs in your implementation and it will be much easier to look at (and even hand-modify) the save game data to help you solve your bugs.

    And if you really need smaller save sizes, finally when you're all done you can just gzip the data before writing it to disk.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,645
    You can do both and IFDEF DEBUG then JSON else BINARY. :) (pseudo code, obviously)
     
    Kurt-Dekker likes this.
  5. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    But on the scale of player data, i would rather use something more secure than JSON or XML because players could easily just g in and edit things easily
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,821
    If is game save, don't bother hassle. Who wants, will crack it anyway.
    If for general game data, then you better of hard code it. Still this can be cracked too.
    If you want something more secure, you may be interested in number of asset, to obfuscate things.
     
unityunity