Question regarding how Prefab saving works

Discussion and help for Easy Save 3
Post Reply
Connor
Posts: 1
Joined: Wed Nov 17, 2021 8:37 am

Question regarding how Prefab saving works

Post by Connor »

Hi all,

I was wondering if I could get some details on how the Prefab saving is supposed to work. I have of course read the documentation regarding it but it is pretty bare bones from what I can see.

And just as a forewarning, I am using the prefab loading because I have a material that cannot be serialized at runtime & it is not in the scene before runtime. I understand that this causes issues with ES3 since there is no reference to pull from but that is why I am looking to use prefabs to avoid having to have a reference to the material at all.

My assumption going into prefab saving was that I would essentially be saving(to json) a referance to a prefab and that prefab would be instantiated instead of the normal ES3.Load workflow of constructing a GameObject based on its serialized data from the save JSON. Its hard to tell given that there are (at least from what I can tell) no examples of using the Prefab saving described in the docs. Only examples of manually handling it which would be fine for my purposes if thats all there is, I just want to use an existing solution if its already been written.

Some more preface for my setup:
I am instantiating Gameobjects at runtime,
When I hit a save button I am collecting all the Instantiated GameObjects in a GameObject[] array
To save them:

Code: Select all

ES3.Save<GameObject[]>(key, array)
When I hit a load button, I am running:

Code: Select all

GameObject[] loadedObjects = ES3.Load<GameObject[]>(key)
I have also tried LoadInto<>() and am getting the same results in my tests.

What does saving a prefab do differently from saving a GameObject?
I see that when I enable saving for prefabs it is actually just adding the ES3Prefab script to my object and running: "GeneratePrefabReferences()"
And I see that when I save the Object using ES3.Save it has a special value in JSON called "es3Prefab" outside of the "components" section.
Which all indicates to me that my initial assumptions that I mentioned above were correct, however when I continue to look at the save JSON I see that ES3 is still serializing the entire object. I was expecting it to stop serializing when it saw the prefab since it can just instantiate the prefab by reference when it loads. And when I go to ES3.Load the prefabbed object, it tries to reconstruct the entire the object based on the Serialized save data.
I assume I'm missing something big here, but I just don't get what saving a prefab is supposed to do given that it seems to just serialize the whole thing and load the entire serialization anyway.

I would really recommend adding example projects for everything described in the docs.
I would also really like to see more of the "nitty gritty" stuff explained on the docs to better inform users how to use the plugin. Like I said, its not even clear to me if I am understanding what the Prefabing Saving is supposed to do since the docs just briefly explain how to do it.

Thanks so much,
Connor
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Question regarding how Prefab saving works

Post by Joel »

Hi Connor,

From a user level, saving a prefab instance and saving a GameObject are done in exactly the same way apart from the step you describe which adds the ES3Prefab. We don’t document what happens underneath in order to not complicate things.

In simple terms, underneath Easy Save loads data into the Components of a prefab instance if it already exists, or creates a new instance of that prefab if it doesn’t.

If you are encountering issues, please could you replicate them in a new project with a simple scene and private message it to me with instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Question regarding how Prefab saving works

Post by Joel »

Hi Connor,
By this, you mean that if the ID of an instance that was saved doesn't exist in the scene it will instantiate a new prefab, correct?
Correct.
Does this prefab process also populate the prefab's components and children's components with the serialized data I am seeing in the JSON?
This is correct. It uses the Components which are already attached to the prefab, or creates new Components if a Component with that ID doesn't exist.
If that is the case, is there a way for me to do this process without saving more data than just the prefab? or without loading that serialized data into the prefab's components.
The easiest way this can be achieved is to follow the 'Auto saving prefab instances' guide here, and then in the Auto Save Prefabs window, unselect all of the Components for the prefab and set the Save Event and Load Event at the top of the window to None (this essentially disables Auto Save).

Then when you call ES3.Save on a GameObject, it will save it according to what was selected in the Auto Save window.

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