Hi,
I sent an e-mail about this yesterday, but after browsing the forums today, I figured it might be a discussion other's could find valuable.
I have a object that has a lot of children that are based off of prefab objects, but are modified at runtime. They have ProBuilder MeshFilter components and I modify each individual mesh as well as their Materials. These objects are mixed in with other prefabs that are saved more or less stock. My approach here followed the "Save and load Prefabs Instantiated at Runtime" example, where I added a ES3 Prefab component to all of the prefabs, then saved these grouped by types. This more or less works, but requires a lot of pre-save and post-save modifications. Specifically, I null out the modified meshes and Materials before saving, then rebuild them after the load, which is expensive and makes saving and loading very slow. What I would prefer to do is either one of the following:
1. Save the actual modified mesh and material instances into the save file. This might be to heavy of a cost, but it would require the least amount of fixup if it can be done with reasonable performance.
2. Simply not save these modified meshes and materials, but save the fact they had the components, so that when they're loaded, I can detect the missing mesh/material and rebuild them.
3. Simply not save the modified components, and re-add them after loading.
The 3rd approach seems like it should be able to be accomplished by attaching a ES3 Game object component in addition the the ES Prefab component, but this doesn't appear to work. I'm guessing the ES3 Prefab overrides the behavior of the other component? What would be your suggestion here?
Also, a side note: It seems to me there is a lack of documentation on the various ES3 Components and their uses. I've not been able to find anything about this in any of the docs. Maybe my search foo sucks though. It'd be really nice to have a breakdown of what each of these do and their use cases.
Thanks much!
Kevin
Saving prefabs with modified components
Re: Saving prefabs with modified components
Hi Kevin, sorry to hear you've been encountering issues.
https://docs.moodkie.com/easy-save-3/es ... nd-warning
Tl;dr: You can't load a reference to something which doesn't exist. So you need to save the Meshes and Textures through a separate ES3.Save call to ensure that they're saved by value, and then load them before loading anything which references them. This ensures that the reference exists before trying to load it.
Note that saving meshes and textures can be very performance and storage intensive, so this should only be done if absolutely necessary (i.e. the mesh/texture data itself is modified at runtime and needs saving and loading).
Regarding the other Components, these aren't directly documented because they should not be added manually under any circumstances. Adding them manually would prevent initialisation from happening. Instead they should only be added indirectly by following the instructions in the documentation (for example the ES3Prefab Component is added indirectly via the Enable Easy Save for Prefab menu item.
All the best,
Joel
I recommend checking that you have warnings enabled in your console in the Editor because in your scenario you should get a warning which points you towards the documentation for doing this:1. Save the actual modified mesh and material instances into the save file. This might be to heavy of a cost, but it would require the least amount of fixup if it can be done with reasonable performance.
https://docs.moodkie.com/easy-save-3/es ... nd-warning
Tl;dr: You can't load a reference to something which doesn't exist. So you need to save the Meshes and Textures through a separate ES3.Save call to ensure that they're saved by value, and then load them before loading anything which references them. This ensures that the reference exists before trying to load it.
Note that saving meshes and textures can be very performance and storage intensive, so this should only be done if absolutely necessary (i.e. the mesh/texture data itself is modified at runtime and needs saving and loading).
3. Simply not save the modified components, and re-add them after loading.
Could you explain how the ES3GameObject Component isn't working? We've had no reports of issues with this. Could you share a screenshot of the inspector for your GameObject showing all of the Components on the GameObject, including the ES3GameObject Component? The ES3GameObject Component should show every Component on your GameObject with a checkbox next to it which you use to select or deselect which Components are saved when saving and loading Components.The 3rd approach seems like it should be able to be accomplished by attaching a ES3 Game object component in addition the the ES Prefab component, but this doesn't appear to work. I'm guessing the ES3 Prefab overrides the behavior of the other component?
The ES3GameObject Component is documented in the Saving GameObjects guide.This shouldn't require any more documentation that noted there because it should just be a case of adding the ES3GameObject Component and selecting the Components, but for some reason this isn't happening for you.Also, a side note: It seems to me there is a lack of documentation on the various ES3 Components and their uses. I've not been able to find anything about this in any of the docs. Maybe my search foo sucks though. It'd be really nice to have a breakdown of what each of these do and their use cases.
Regarding the other Components, these aren't directly documented because they should not be added manually under any circumstances. Adding them manually would prevent initialisation from happening. Instead they should only be added indirectly by following the instructions in the documentation (for example the ES3Prefab Component is added indirectly via the Enable Easy Save for Prefab menu item.
All the best,
Joel
Re: Saving prefabs with modified components
Hi Joel,
Thanks so much for the quick reply, that's really helpful. I've put a ton of time into this today and have discovered a lot, but I think I must still be misunderstanding some key concepts.
For example, in order to keep the association with the initial prefab, I'm now instantiating my objects using PrefabUtility.InstantiatePrefab. This works great for objects that don't modify their Materials because it just saves the prefab reference and this is matched up fine when loaded. However, using ES3.LoadInfo or Load does not keep this prefab link, so any following saves will try to save instances of the Materials again. In your Prefab example, you use Instantiate to create these instances, so they are detached from their original prefab. Is this intentional, or am I missing something?
There are other advantages to keeping those links intact, so I'm hesitant to go that route, but it seems like that's the way this is intended to be used?
As for my issue with the ES3GameObject, things seem to be working now that I re-added all the ES3Prefab components through the tool, so that's a win. However, I would like to be able to add ES3Prefab through code. Will this work for that?
ES3Prefab es3pf = go.AddComponent<ES3Prefab>();
es3pf.GeneratePrefabReferences();
mgr.AddPrefab(es3pf);
Or is there more that need to be done?
Thanks again for your time, I realize that is limited and I appreciate your help!
Thanks so much for the quick reply, that's really helpful. I've put a ton of time into this today and have discovered a lot, but I think I must still be misunderstanding some key concepts.
For example, in order to keep the association with the initial prefab, I'm now instantiating my objects using PrefabUtility.InstantiatePrefab. This works great for objects that don't modify their Materials because it just saves the prefab reference and this is matched up fine when loaded. However, using ES3.LoadInfo or Load does not keep this prefab link, so any following saves will try to save instances of the Materials again. In your Prefab example, you use Instantiate to create these instances, so they are detached from their original prefab. Is this intentional, or am I missing something?
There are other advantages to keeping those links intact, so I'm hesitant to go that route, but it seems like that's the way this is intended to be used?
As for my issue with the ES3GameObject, things seem to be working now that I re-added all the ES3Prefab components through the tool, so that's a win. However, I would like to be able to add ES3Prefab through code. Will this work for that?
ES3Prefab es3pf = go.AddComponent<ES3Prefab>();
es3pf.GeneratePrefabReferences();
mgr.AddPrefab(es3pf);
Or is there more that need to be done?
Thanks again for your time, I realize that is limited and I appreciate your help!
Re: Saving prefabs with modified components
Hi there,
However, the code you're doing would indeed do this. You would also need to set the manager as dirty (EditorUtility.SetDirty(mgr);) in order for Unity to persist the changes. However, this isn't a use case that we've tested so this workaround is provided without warranty.
All the best,
Joel
This is an Editor method, so you can't use this at runtime outside of the Editor.I'm now instantiating my objects using PrefabUtility.InstantiatePrefab.
All prefab links are intentionally broken by Unity at runtime (regardless of whether you use Easy Save), and Easy Save is a runtime save and load asset, not an Editor serializer. Are you trying to use Easy Save to save and load Editor data?However, using ES3.LoadInfo or Load does not keep this prefab link
Which prefab example is this? Generally you only use instantiate to create your object for the first time. When loading, you let Easy Save create the instance of the object.In your Prefab example, you use Instantiate to create these instances
We don't recommend doing this. However, if you do this, you should only do it from an Editor script, not at runtime (because the purpose of it is to create a persistent reference, which would be impossible at runtime).However, I would like to be able to add ES3Prefab through code. Will this work for that?
However, the code you're doing would indeed do this. You would also need to set the manager as dirty (EditorUtility.SetDirty(mgr);) in order for Unity to persist the changes. However, this isn't a use case that we've tested so this workaround is provided without warranty.
All the best,
Joel
Re: Saving prefabs with modified components
Great, thanks again Joel. I hasn't realized that the prefab linking was intended for the Editor only.
With that info, this is all working now!
Thanks so much for your help! Hopefully I won't need to take more of your time.
Kevin
With that info, this is all working now!
Thanks so much for your help! Hopefully I won't need to take more of your time.
Kevin
Re: Saving prefabs with modified components
Glad that's all working for you now Kevin 
All the best,
Joel

All the best,
Joel