How to save/load variables + ScriptableObject reference?

Discussion and help for Easy Save 3
Post Reply
Shadow
Posts: 3
Joined: Tue Feb 16, 2021 1:12 pm

How to save/load variables + ScriptableObject reference?

Post by Shadow »

Sorry for the newbie question, I'm trying to learn how to use Easy Save.

I have a "Character" class that is used in my "CharacterParty" Class.

Code: Select all

public class Character
{

    [SerializeField] CharacterBase _base;
    [SerializeField] int level;


    //reference to our CharacterBase(ScriptableObject)
    public CharacterBase CharacterBase {
        get
        {
            return _base;
        }


    }
    public int Level {
        get
        {
            return level;
        }
    }

    public int HP { get; set; }
 }
    
And then a CharacterParty class that is attached to a gameobject. And this class will be used to determine whos in my party.

Code: Select all

public class CharacterParty : MonoBehaviour
{
    [SerializeField]List<Character> characters;

    //Property for list of all characters
    public List<Character> Characters
    {
        get
        {
            return characters;
        }     
    }
}
So my question is, how can I save the references to my list of Characters in my CharacterParty class? because in my game you can switch out party members so I want to make sure that when they save and load, the party members they had when they saved is there too as well as the stats like HP that is shown in the Character class.

A step by step example would really help me understand it, Thank you.
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save/load variables + ScriptableObject reference?

Post by Joel »

Hi there,

You would simply use ES3.Save and ES3.Load to save and load it as described in the Getting Started guide:

https://docs.moodkie.com/easy-save-3/getting-started/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Shadow
Posts: 3
Joined: Tue Feb 16, 2021 1:12 pm

Re: How to save/load variables + ScriptableObject reference?

Post by Shadow »

I have seen that and I guess the variables bit seem okay to save and load, but how about the game object reference saving & loading? As I mentioned before I have scriptableobjects containing in my CharacterParty class as list of characters. What are the steps needed to save those game object references, there are certain things I can make out from the doc but some things are still unclear.

doing something like this doesn't seem to do anything. And when loading it, it gives null exception errors.

Code: Select all

 public void EasySaveList()
    {
        ES3.Save("party", characters);
    }
    public void EasyLoadList()
    {
        characters = ES3.Load("party", characters);
    }
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save/load variables + ScriptableObject reference?

Post by Joel »

Hi there,

Please could you show me the full stack trace of the errors you're getting?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Shadow
Posts: 3
Joined: Tue Feb 16, 2021 1:12 pm

Re: How to save/load variables + ScriptableObject reference?

Post by Shadow »

Its working now. sorry about that! I think It had something to do with Unity, after restarting Unity, it seems to work now.

On a side note, is it necessary for everything in your scene to be referenced for the Easy Save 3 Manager in the scene? Theres tons of stuff it automatically referenced but I feel like some aren't necessary and will huge amounts cause any performance issue once the game is built?

If its okay to remove some that are not needed, how can you remove it, just switch it to none??
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save/load variables + ScriptableObject reference?

Post by Joel »

Hi there,

The reference manager simply contains references to anything in your scene which can be referenced. These won't be saved unless you tell Easy Save to, so the reference manager won't have any impact on performance.

Note that the reference manager is required if you're saving reference types, which in your case you are.

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