High Level Save Manager

Discussion and help for Easy Save 3
Post Reply
User1221
Posts: 1
Joined: Mon Aug 12, 2019 2:11 pm

High Level Save Manager

Post by User1221 »

New to ES3 and I have looked over the documentation, but I don't think it can answer my question.

Is anyone implementing a high level save system? Meaning, that when some event occurs, (beating a boss, collecting a treasure, etc..) all the ES3 nodes are told to save? Thinking in terms of an RPG, collecting a new sword might save that to inventory and then ES3's save function is called, I would like for ALL save functions to be called at the same time. Saving the players health, money etc.. at that point.

I thought about creating some system, that has references to all the possible objects that can be saved, and then calling some event that will trigger the save event on all the object. But that seems like mistakes waiting to happen, like forgetting to add some random item.

I would like to be able to do the "auto save" when the user hits a checkpoint, or leaves the current scene, etc.. That way if the player dies, I can reload from their last save state. Any any progress is reset.


How is everyone else doing it? Does something like that exist?
Exonto
Posts: 5
Joined: Mon Aug 12, 2019 3:05 am

Re: High Level Save Manager

Post by Exonto »

Whatever you are saving, you will need to have a reference to. I am also saving an inventory system (among other things), however, there is no chance of me forgetting to save a particular item. This is because rather than having individual references to each item and saving those items individually, I instead have a reference to the inventories that contain those items. The inventory will have a reference to all of its items, so there's no way for one to be accidentally missed. If you don't already, make an inventory class that has a list of all the items in it.

But in general what I've done in the past with other serialization libraries is to make a "save service" which is responsible for saving and loading the game. It might have a method called SaveInventory(Inventory inventory, string key) which you can call to save any inventory you want, not just the player's and you won't have to save the entire game to do so. I personally like to store a list of every single inventory in the entire game so that I can save all inventories at once. The way you do that is up to you. I do this for just about everything that needs to be saved. I store a list of all the creatures, a list of all tiles in the tilemap etc. This is useful for more than just saving.

You are correct when you suggest an event system. In my opinion, that is definitely the way to go.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: High Level Save Manager

Post by Joel »

Hi there,

It's perfectly possible to make a "save service" with Easy Save, and I think the majority of users actually opt for this. Let's say that we wanted a save service which saved whenever the user enters a trigger, and loads when the scene starts. This would be as simple as this:
using UnityEngine;

public class SaveService : MonoBehaviour
{
    void OnTriggerEnter(Collider other)
    {
        // Save your inventory, assuming that its fields are supported types.
        ES3.Save<Inventory>("inventory", GameObject.Find("Inventory").GetComponent<Inventory>());
        // You could add other ES3.Save calls here to save other things.
    }

    void Awake()
    {
        // Load when the scene loads.
        ES3.Load<Inventory>("inventory", GameObject.Find("Inventory").GetComponent<Inventory>());
    }
}
This would be an example of a simple save service.

And thanks Exonto for your response, very helpful to hear how you're doing it.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply