Why use ES3Prefab?

Discussion and help for Easy Save 3
Post Reply
NikNev
Posts: 4
Joined: Wed Jan 04, 2023 4:34 pm

Why use ES3Prefab?

Post by NikNev »

Hi,

Whether I enable "Easy Save for prefabs" or not, the way I save/load gameobjects is still the same with `ES3.Save(mykey,myGameObject)'.

I thought the save file size would reduce when using ES3Prefab, but in some quick tests I made, it increased from 156kb to 205kb uncompressed, 13kb to 19kb compressed (my tests was quick n dirty tho).

So what's the purpose of using ES3 Prefab?

I just bought ES3 yesterday (and it's great btw). I'm just trying to wrap my head around it and get a sense of how I should implement it into my project.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why use ES3Prefab?

Post by Joel »

Hi there,

Sometimes there are Components which cannot be serialized at runtime, or Components/children which you don't want to be saved but want to be restored with default values when loading. ES3Prefab allows these to be instantiated without having to load them from file. It also ensures that the prefabs dependencies can be stored by reference.

ES3Prefab doesn't change what gets saved, it only specifies an object to instantiate to load the data into, and adds it's dependencies into the reference manager. It will still save all explicitly supported Components.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NikNev
Posts: 4
Joined: Wed Jan 04, 2023 4:34 pm

Re: Why use ES3Prefab?

Post by NikNev »

..or Components/children which you don't want to be saved but want to be restored with default values when loading.
So saved gameobjects with ES3Prefab will always be loaded back with default values? What about without ES3Prefab?

I'm confused now. Just now I did some testing with and without ES3Prefab - and values in public fields (like a string) that are changed on runtime - those changes weren't being saved in either scenario. I thought that all supported types were automatically saved when saving a gameobject.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why use ES3Prefab?

Post by Joel »

So saved gameobjects with ES3Prefab will always be loaded back with default values? What about without ES3Prefab?
GameObjects with ES3Prefab will first be instantiated from the prefab (which will include all of that prefab's Components). Easy Save will then load any Components which were saved (i.e. any Components which have been explicitly supported either natively or have had an ES3Type created via the Types panel).

If you were to save a GameObject without an ES3Prefab and then load it, only the Components which have been explicitly supported either natively or have had an ES3Type created via the Types panel will be restored.
I'm confused now. Just now I did some testing with and without ES3Prefab - and values in public fields (like a string) that are changed on runtime - those changes weren't being saved in either scenario. I thought that all supported types were automatically saved when saving a gameobject.
Did you add support for the Component in the Types panel? For more information on what gets saved when saving and loading GameObjects please see the Saving and Loading GameObjects guide:

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
NikNev
Posts: 4
Joined: Wed Jan 04, 2023 4:34 pm

Re: Why use ES3Prefab?

Post by NikNev »

Thanks, things are clearer now. I hadn't added support with ES3Type, didn't think I needed it.

If I save a MonoBehaviour that I've written (e.g. ES3.Save(id,myComponent);) - do I always need to add an ES3Type for it, or only when there's a field/property type that ES3 doesn't auto support?

The approach I'm leaning towards using would be something like this. Does this sound reasonable or am i missing something?

Saving

Code: Select all

foreach gameObject i want to save
1) Save each component
2) Save prefab (with ES3Prefab or save a reference that I can use to instantiate)
Loading

Code: Select all

load level
foreach saved gameobject
1) instantiate prefab (or load with ES3Prefab)
2) load each component.
Then if there's some type in a component that's not supported, i'll either use a custom ES3Type or have some interface on my components that allow them to define if they want to be saved/loaded in a custom way.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why use ES3Prefab?

Post by Joel »

Hi there,
If I save a MonoBehaviour that I've written (e.g. ES3.Save(id,myComponent);) - do I always need to add an ES3Type for it, or only when there's a field/property type that ES3 doesn't auto support?
If you're saving the Component directly (rather than as part of a GameObject) then you only need to add an ES3Type for it if there's a field/property that isn't automatically supported.
The approach I'm leaning towards using would be something like this. Does this sound reasonable or am i missing something?
This sounds reasonable. You will want to use ES3.LoadInto to load the data into the Component on your prefab, otherwise Easy Save will create a new instance of the Component.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NikNev
Posts: 4
Joined: Wed Jan 04, 2023 4:34 pm

Re: Why use ES3Prefab?

Post by NikNev »

Great thanks :)
Post Reply