Confused on "How to start"

Discussion and help for Easy Save 3
Post Reply
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Confused on "How to start"

Post by KEM4 »

Hello. Recently purchased the asset and the documentation seems a bit thin.

I experimented with the values and yes, I get it working, somehow, on some level but have a really hard time understanding the features here.
My game consists of characters (enemy and player group) and I`d like to keep the player group HP always persistent. The character consists of a scriptable object that has such values as max hp and damage. The prefab holds the current HP value but that would not be an issue to move it to a scriptable object as I would like to extend the saving in the future to save the current state of the damage too.
The next thing I would like to save/load is the "list" of active units in the field. At the moment that also sits in the scriptable object.

The question here is ... how?
Do I have to manually create some IDs for references and create my own keys? Do I use the "autosave feature"? I explored some "types" section that creates some scripts, but what do I do with them is totally unclear for me? Do i need to attach them? Do I need some setup for auto save then?
The goal is simple saving but having hard time to understand the attachment here.
I added "ES3prefab" at the beginning to my Character prefab but that seems to give just a generated Id, well I can do that too, fair, then I`d try to use ES3.Save with key but the keys seems to be just a unique "global" type of key, meaning that I have to pull in the reference to the ES3prefab to get the ID.
The values are stored as flat JSON as I saw in the .es3 file that got me kinda confused. Is there some nested approach there possible?

Apologies, but it's hard for me to get my head around.
Any tips how I could save it and expand it as I need those values to be saved between scenes and all the time?

P.S. I am not a fan of singletons so I keep my project clean of the scripts and codes that looks "weird" for me.
User avatar
Joel
Moodkie Staff
Posts: 4871
Joined: Wed Nov 07, 2012 10:32 pm

Re: Confused on "How to start"

Post by Joel »

Hi there,

If I understand correctly, you should just be able to save and load your ScriptableObject. I.e.

Code: Select all

// To save
ES3.Save("key", yourScriptableObject);

// To load
yourScriptableObject = ES3.Load<YourScriptableObjectType>("key");
As long as there's a reference to your objects prior to runtime, you don't need to add them to the reference manager as this will be done automatically.

If you indeed want to save the prefab, there's information on doing this in the saving and loading GameObjects and Prefabs guide:
https://docs.moodkie.com/easy-save-3/es ... s-prefabs/
The values are stored as flat JSON as I saw in the .es3 file that got me kinda confused. Is there some nested approach there possible?
I don't know what you mean by this. Could you clarify?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Re: Confused on "How to start"

Post by KEM4 »

Thank you for the quick reply.

Well, I guess because I saved a single integer value manually the key had to be unique because if I used ES3.Save("Health", gameobject.Health) it saved it under the key "Health" and objects that inherited got the same HP value.
Writing this answer down actually starts to make some sense for this.
If I do not wish to save ALL the fields of the scriptable object, I would need to use the "ES3NonSerializable" or so classes, do I understood that correctly?

The last part now doesn`t matter as I understood why it actually was like that.

When saving the scriptable objects, will it keep the default values set inside the editor if the values/scriptable object were not found or how the loading could be "automated" in some sense?
Meaning ... I saw this "LoadInto" function that I understand could be used to load from the storage, and assign the values instead of manually getting the scriptable object "copy" or how the loading could be done more efficient?

I understand that it comes down to specifics but where do you recommend to save & load values for scriptable objects?
User avatar
Joel
Moodkie Staff
Posts: 4871
Joined: Wed Nov 07, 2012 10:32 pm

Re: Confused on "How to start"

Post by Joel »

KEM4 wrote: Mon Mar 22, 2021 10:22 amIf I do not wish to save ALL the fields of the scriptable object, I would need to use the "ES3NonSerializable" or so classes, do I understood that correctly?
That is correct.
KEM4 wrote: Mon Mar 22, 2021 10:22 am Meaning ... I saw this "LoadInto" function that I understand could be used to load from the storage, and assign the values instead of manually getting the scriptable object "copy" or how the loading could be done more efficient?

I understand that it comes down to specifics but where do you recommend to save & load values for scriptable objects?
I'm not sure I understand the question. If you want Easy Save to create the instance of the ScriptableObject if it doesn't exist, you should use ES3.Load. If you have an instance you want to load the data into, you should use ES3.LoadInto.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Re: Confused on "How to start"

Post by KEM4 »

Thank you.

My question for the "where" is where such logic "ES3.LoadInto" should be put in? OnEnable/OnDisable for scriptable objects?
The recommendation for the "keys" would be what? Is there a pre-defined option to generate unique ID/keys for ScriptableObjects that could be given the save system as a "key" to store the scriptable object?
Well its hard to wrap my head around really about WHERE that stuff is recommended to put in?

What about default values? I want to store the current HP for example but if the value was not stored, set it to "MaxHP" value within the same scriptable object?
User avatar
Joel
Moodkie Staff
Posts: 4871
Joined: Wed Nov 07, 2012 10:32 pm

Re: Confused on "How to start"

Post by Joel »

Hi there,

That depends on when you want the data to be loaded. If you want the data to be loaded when the object is enabled, you would put it in OnEnable. This very much depends on your project.
The recommendation for the "keys" would be what? Is there a pre-defined option to generate unique ID/keys for ScriptableObjects that could be given the save system as a "key" to store the scriptable object?
Regarding keys, you simply need to provide the same key when loading as you used when saving (exactly like a C# dictionary). You shouldn't need to generate a unique ID ... you can just use something like "MyScriptableObject". If you've got multiple ScriptableObjects, then you would save an array of them rather than each one to an individual key.
Well its hard to wrap my head around really about WHERE that stuff is recommended to put in?
I'm afraid I don't understand the question.
What about default values? I want to store the current HP for example but if the value was not stored, set it to "MaxHP" value within the same scriptable object?
Easy Save will use the default value provided when that ScriptableObject is constructed. If you want to provide your own default value, you should use ES3.KeyExists to check whether there is data to load, and assign your own defaults if not.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KEM4
Posts: 6
Joined: Mon Mar 22, 2021 9:07 am

Re: Confused on "How to start"

Post by KEM4 »

Thanks for the support here. I managed to find some suitable solutions, understand things that happen under the hood, and how to control this beast.
Post Reply