Search Unity

Official Save System

Discussion in 'Open Projects' started by bronsonzgeb, Feb 11, 2021.

  1. bronsonzgeb

    bronsonzgeb

    Unity Technologies

    Joined:
    Aug 10, 2020
    Posts:
    101
    Let's start talking about a save system!

    I'd like to take some time to consider what we need to save in the context of the project as a whole. What do we need to save? The important things that come to mind are Inventory and Quest Progress, but given that the community knows more about the project than I do right now, I'd like to invite y'all to weigh in on this. Then once we know what we're aiming for we can build a plan.
     
    Amel-Unity and cirocontinisio like this.
  2. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hey @bronsonzgeb, have you started to work on one? I have created my implementation:

    As far as I know, there are three kinds for save systems.

    Manual Saving

    This kind of saving is done by pressing a save button in the options menu. Then the game progress upto that point of time is saved.

    Checkpoint, Automatic saving

    This is done automatically, the player don't need to worry about any sort of saving. The game will be automatically save when certain cutscenes are reached, or when game progress reaches at centain point.
    In our case, we can save game when a Quest is completed, or a location is completed.

    Positional, Save Point Saving
    This is that kind, which I consider best, and what I have implemented now, in which there are SavePoints, maybe one in each Location/Scene. When player reaches and confirms, the game is saved upto that point of progress.

    Now, my implementation.

    I have used the Third type, the save point.
    I have created a save point in each location scene. It has a new tag "SavePoint". New type of interaction, called Save is added. If player arrives in the range of a save point, the interaction HUD is displayed. And if E key is pressed, the SaveGame method on the SavePoint is called.
    It raises a SaveGameEvent which is a GameobjectEventChannelSO, where the gameObject is that savepoint.
    In the SaveManager, which is in the PersistenceScene, the event is listened and the real saving occurs.

    It currently saves in which location is the player saving, for which I created a new RuntimeAnchor, called LocationAnchor.
    It is set by the spawn system the current Location. So the spawnSystem is also modified for a field called "this location". So PlayerLocation is Updated every time Player changes location.
    It also saves the SavePoint gameObject position (for spawing player there upon loading) and the player Inventory.

    Now for loading, I think the game should be loaded when the continue button in the MainMenu scene is pressed. But for debugging, I added a load button. Pressing this will raise LoadGameEvent, which is a VoidEventChannelSO.

    In the SaveManager, LoadGameEvent is listened and loads the game. It first loads the scene (location) in which the player saved the game. Then sets the player position accordingly to the SavePoint. For this it listens to the PlayerInstantiated Channel.
    And then restores the playerInventory.

    There are some conflicts. And I know as when I started to work on, Interaction Manager was changed after that (and many more, such as gameplay scene). @cirocontinisio, how do I fix them? (I haven't ran into this issue yet).

    Here is the PR:
    https://github.com/UnityTechnologies/open-project-1/pull/364

    I welcome Reviews and suggestions.
     
  3. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    You need to sync your fork with the main project. Here is how : https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork. In your case the upstream url will be the project's original repo. After following those steps, you will get a merge conflict in InteractionManager.cs since it was changed both by you as well as in the main repo. You will have to manually merge the code in that class, save it and commit it again.
     
  4. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
  5. JoaoSantos

    JoaoSantos

    Joined:
    Mar 31, 2014
    Posts:
    20
    Hey folks. When a tried running the project in the first time, a log error appear for me.

    upload_2021-3-28_19-53-29.png

    This error appear when I run the game in different scenes (like the Beach for example).
    Checking the script FileManager i see in the MoveFile function that we create a new backup file. But as I running in the first time, to first file don't existe, raising a error.

    I made a additional conditions to check if the first file exist and worked greate to me.
     
  6. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Great @JoaoSantos, Have you created a Pull Request?
     
    JoaoSantos likes this.
  7. JoaoSantos

    JoaoSantos

    Joined:
    Mar 31, 2014
    Posts:
    20
    Not yet, I will create now. I will report an issue in the github;
     
  8. JoaoSantos

    JoaoSantos

    Joined:
    Mar 31, 2014
    Posts:
    20