Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Save and load systems for Metroidmania

Discussion in 'Scripting' started by liquidsht, Aug 3, 2020.

  1. liquidsht

    liquidsht

    Joined:
    Jun 4, 2020
    Posts:
    49
    I just started to look at saving and loading for my metroidvania but not sure if I have all the concepts down.
    I understand for simple things such as game settings, you can use player prefs to store and for more complicated things I would need to have systems that creates files to load from.

    1. Let's say I have 100 chests in my game, i would need to have an ID for each chest and a bool for each to track whether they have been opened or not? so for each boss, each door, and possibly each unique item in the game, I will need an ID and bool to keep track? so for games like hollow knight that would be thousands of lines just to keep track?

    2. For inventory, I need to have a bool for each of the items and an int for each stackable items? so pseudo code would be:
    bool uniqueSword = true
    int commonApples = 50
    or is there a way to consolidate so instead of 100 lines for 100 items, I can just save to a file and load that file when loading the progress save?can inventory assets on unity store simplify this?

    Hope the questions make sense. Thanks.
     
  2. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    1000’s of values are trivial to save. You could serialize hundreds of thousands of bits of information with negligible write times.

    Best bet is write some code and benchmark it and then take it from there but you are correct in the approach. You could just use a single value for your inventory. The default 0 means not available and then anything above 0 would be the quantity etc.
     
  3. liquidsht

    liquidsht

    Joined:
    Jun 4, 2020
    Posts:
    49
    Thanks Nic, I am not too worried about performance since my game is 2D and doesnt use too much resources. I was hoping there is a safer/quicker way to organise thousands of lines for items, switches, bosses, doors , etc and the bugs that come with entering them manually. it would be so easy to have placed 100 items in game but only actually have 99 of them with ID.
     
  4. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    Your best bet is automating this. I think it depends how you create the level itself. you could also give each object a unique id to make sure you don’t have conflicts.
     
  5. liquidsht

    liquidsht

    Joined:
    Jun 4, 2020
    Posts:
    49
    How would I go about automating this? I have gone through a few tutorials but have not see anything about how this can be automated. Do you know of any tutorials or info on this? Would really appreciate it if you could point me to some resources. Thanks.
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    It's a bit of a hassle, but not that hard.

    What we did for World to the West was that each pickup had a unique ID that consisted of:
    - Level Name
    - Pickup type
    - ID

    So the second health powerup on the level Lake East would have the ID "lake_east/health_powerup_2"
    Using the level name made the save file a lot easier to read and debug, and also makes it easier to ensure unique names - you can fix levels with duplicate names one at a time.

    In each pickup's inspector's OnEnable, we scanned the level for other objects with the same type, and made sure the names were unique. We also had a script running in PostProcessScene that made the same thing happen, to fix instances where designers had duplicated items. That pretty much covered it.

    Our save file system allowed us to register arbitrary string/bool pairs - so it was similar to a normal Dictionary<string, bool> or a HashSet<string> (at least for pickups). So when picking up the item, you added the "lake_east/health_powerup_2"/true to the save file, and then when the level was loaded, the item deleted itself if that string was in the current save file with the value true.