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

Saving progress architecture

Discussion in '2D' started by rizenmusic, Mar 17, 2021.

  1. rizenmusic

    rizenmusic

    Joined:
    Oct 2, 2019
    Posts:
    23
    Hi! I want to implement a save system in my game early and need an advice about variables.

    My game is metroidvania type game, so I have player, enemies, many scenes, states of pickups, states of bosses, dialogues state etc. How do I save all of this? I mean, do I need to save all my data in just one static script or is there other options? For example, I've got a player. It has speed, attack power, abilities and more. And it's handy to have all them variables in the corresponding scripts. But to save data from 50 different scripts is not the way, am I right? Then how do I handle this? Where should all my variables be stored?

    Thanks for help. As a junior developer architecture kind of questions are the hardest for me.
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    create a class that has all those variables and then serialize and deserialize as needed. you can use binary formatter or json for serialization
     
    rizenmusic likes this.
  3. rizenmusic

    rizenmusic

    Joined:
    Oct 2, 2019
    Posts:
    23
    That I know. But do I need to use this class in all my scripts that use variables from it? Like, do my PlayerController class needs to have it's own variables that, if changed, change SaveData class variables? Or do I need to inherit from that class? If I have a 1000 variables in one class, it doesn't seem very convenient to use it as a primary class for all the routine needs of my game. Then how do I approach to this?
     
  4. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    when you want to save make the class collect all your variables from across your scripts.

    When you want to load make the class assign all the variables to each of your scripts
     
  5. Bean_Office

    Bean_Office

    Joined:
    Jun 18, 2018
    Posts:
    14
    Heres an amazing tutorial by brackeys: