Objects holding scripts I made

Discussion and help for Easy Save 3
Post Reply
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Objects holding scripts I made

Post by eovento »

Good morning, Joel! Good morning, everyone! :)

In my game there is a parent object which holds a huge number of instantiated objects that become children of this one.

Each of this instantiated objects have a script made by me, and on this script there are about 50 variables (mostly floats, integers and strings).

The reason I need Easy Save in this project is to save the parent object - the one holding all children. Then on the next time I run the game, this parent object will be loaded with all the children inside of it. And each child holding the script I mentioned, full of variables.

I'm seeking for help because it's only partially working. All children are loaded, but they are empty. The script inside them (which is the only reason I need the objects) is not saved. So, when it's loaded, I have the parent object full of empty children inside of it.

Before coming to the forum for help, I tried to find the solution to this by myself and read about "manage types", as I have to add them beforehand. But all information I found was really poor on this. And "manage types" menu is only found under Easy Save 2, and I am using Easy Save 3. (The presence of both versions is also very confusing, but I don't wanna lose the focus on this now.)

Please, if you could orient me on how to store this object holding all it's children, keeping the script I made and the values to all variables inside each of the children, I would be very grateful. :)

And I wish you all a good Friday! ;)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Objects holding scripts I made

Post by Joel »

Hi there,

Have you followed the instruction in the Saving and Loading GameObjects guide, and particularly the Prefab Instances section if any of your GameObjects are Prefab Instances created at runtime?

https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Re: Objects holding scripts I made

Post by eovento »

Thank you, Joel, for quick reply! :)

I was following this guidance for the parent object only (as, technically, this is the only object I was saving). Now, I have allowed (Easy Save for prefab) on instantiated objects as you suggested and it indeed recorded the script inside each children. But it's not recording the values of each (of the many) variables in this script - present on each (of many!) children objects. I might be still missing something.

(Also, another tricky thing is that when objects get loaded, they run Start and Awake again - which, depending on each project, can get really messy and unexpected behaviours. So I made a boolean to avoid them to run everything on Start() on each session it's reloaded.)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Objects holding scripts I made

Post by Joel »

Hi there,

Would you be able to check that the fields you want to save are supported? You can find out what types of field will be supported automatically here: https://docs.moodkie.com/easy-save-3/es ... ted-types/

With regards to Start and Awake being called, this is expected behaviour whenever a new Component is created in a scene and is defined at Unity's end rather than ours.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Re: Objects holding scripts I made

Post by eovento »

Good morning, Joel!

I’m still struggling to save my variables.
You asked if they are valid. When you ask this, you mean the component or the variables themselves?
It’s a component I made with basic variables: ints, floats and strings only.

Trying to illustrate in a very simple example, it’s like I have a parent gameObject called “Enemies” and along the game a lot of enemies are going to be instantiated as children of this gameObject. Each of these children have a EnemyHealth.cs script on them, with an integer called “energy”.

Then... when the user quits the game, I would like to save all enemy objects (children of “Enemies”) and their energy variable by saving only the parent gameObject “Enemies” (although all instantiated children have also an Auto Save script attached on them).

They all have ES3 Auto Save script attached - both the parent already in Hierarchy and all prefabs who are going to be instantiated (save children is checked). Also, all prefabs have Easy Save for Prefab enabled.
But, when I load, I can see all children, but the variable value wasn’t saved on any of them.

I’ve been reading and re-reading it, but I can’t find a solution for this on Documentation.

-

I know it’s Sunday, and no urgencies here! Enjoy your weekend, and if I finally figure it out before Monday, I drop another message.

All the best!
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Re: Objects holding scripts I made

Post by eovento »

OK, I'm getting there.
Apparently, what I was missing was the creation of ES3Type.
Now I think it's gonna work fine. :)

Is there a way of seeing all the entries/keys I have created on the project? And also a way of deleting them all at once - something like a "Reset" for Easy Save?
Thank you!
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Objects holding scripts I made

Post by Joel »

Hi there,

Glad you managed to find the solution :)

You can open up the save file and see the keys in JSON format by going to Window > Easy Save 3 > Tools > Open Persistent Data Path. From there you can also delete the save data.

In code you can get all of the keys for a file using ES3.GetKeys, and delete all of the keys within that file with ES3.DeleteFile. Similarly, you can get a list of all of the files in the persistent data path using ES3.GetFilenames.

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