Saving and loading prefab instances alongside pooling

Discussion and help for Easy Save 3
Post Reply
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Saving and loading prefab instances alongside pooling

Post by Joel »

Hi Joel, thanks for the assistance unfortunately the issue seems to be when using a pooling system from another asset called Poolboss, when loading a scene it auto spawns all the prefabs in the pool list when auto saved. Is there any help you can possibly provide with this? I fear that it may be an issue which neither asset creator can provide support for if they both conflict with each other...

Just to clarify, I added the es3 component by right clicking the prefab, selecting easy save, selecting the option to enable easy save.
Aside from this everything works amazing and im excited to use the tool as it makes saving a breeze, I just have this concern about pooling in the project. Thanks!
Hi there,

I understand. In this case it wouldn't be possible for Auto Save to distinguish between those objects in the pool and those in use, so it would be necessary to use code instead so you can define which prefab instances you want to save. If you're using pooling, you would also need to ensure that the pooling system is creating instances of the prefab rather than Easy Save.

There's an example of something similar in this example:
https://moodkie.com/forum/viewtopic.php?f=16&t=1438

Instead of using Unity's Instantiate method as showing in this example, you would instead use your pooling system's instantiate method. Let me know if you have any questions and I'll be happy to assist.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sebasrez
Posts: 12
Joined: Fri Mar 04, 2022 1:57 pm

Re: Saving and loading prefab instances alongside pooling

Post by sebasrez »

Joel wrote: Thu Oct 13, 2022 8:09 am Hi there,

I understand. In this case it wouldn't be possible for Auto Save to distinguish between those objects in the pool and those in use, so it would be necessary to use code instead so you can define which prefab instances you want to save. If you're using pooling, you would also need to ensure that the pooling system is creating instances of the prefab rather than Easy Save.

There's an example of something similar in this example:
https://moodkie.com/forum/viewtopic.php?f=16&t=1438

Instead of using Unity's Instantiate method as showing in this example, you would instead use your pooling system's instantiate method. Let me know if you have any questions and I'll be happy to assist.

All the best,
Joel
Thanks, so to understand clearly I can't use auto save because of the pooling system and would have to do saving manually for any pooled prefabs? I may need a simplified explanation haha so on play, ten of my prefabs are instantiated and disabled (which is using the my pooling system as you mentioned) so when I turn one on and save it turns them all on im assuming because of the ID, correct? I'm not sure what the difference is in the instantiate method or how to ensure that the pooling system is creating instances of the prefab rather than easy save.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving and loading prefab instances alongside pooling

Post by Joel »

Hi there,
Thanks, so to understand clearly I can't use auto save because of the pooling system and would have to do saving manually for any pooled prefabs?
This is correct, because the pooling system is responsible for instantiating these objects, meaning when we try to create instances ourselves it will cause issues.
I may need a simplified explanation haha so on play, ten of my prefabs are instantiated and disabled (which is using the my pooling system as you mentioned) so when I turn one on and save it turns them all on im assuming because of the ID, correct?
As long as you have selected the 'active' field in the Auto Save settings the enabled/disabled state of these GameObjects should be saved and loaded correctly. I.e. they'll have the active state as they had when they were saved.
I'm not sure what the difference is in the instantiate method
Pooling systems should provide you with a way of getting an instance of your prefab (i.e. similar to Unity's Instantiate(object) method, except it takes an object from the pool or creates a new one. However, I wouldn't be able to say exactly how this is done with the pooling asset you're using as I have no experience with it.
... or how to ensure that the pooling system is creating instances of the prefab rather than easy save.
In the example I linked you would replace the call to Unity's Instantiate(object) method with your pooling system's Instantiate(object) method.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sebasrez
Posts: 12
Joined: Fri Mar 04, 2022 1:57 pm

Re: Saving and loading prefab instances alongside pooling

Post by sebasrez »

Its so close! The only issue is that it keeps instantiating the prefabs on the start. My pool manager starts with 3 deactivated prefabs on runtime. I stop and start the scene and I have 6, etc etc. Like your demo scene I can activate them and they will stay, which is great progress, but a few things still confuse me...

-The prefabs are multiplying per play/load.
-I have to at least turn on one of the check boxes for the prefab on the prefab section in the autosave section in the easy save settings window. (I had to do this with the prefabs in the demo scene to get them to work as well even though I thought it wasn't supposed to use autosave per our last message)
-Deleting in the demo only works for objects that were created on that scene, not the loaded prefabs. Alternatively, in my pooling system, deactivating a prefab still instantiates it and activates it when loading. (while also creating the new 3 deactivated prefabs in the pool)

I did change the script to instantiate based on the pooling system so that does work but I have it sometimes bugs out and loads prefabs from other tests even when the data path is cleared. I have to sometimes test on fresh prefabs and fresh easy save 3 managers to get it to work. And honestly thanks for the assistance, I really appreciate the help you have given thus far.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving and loading prefab instances alongside pooling

Post by Joel »

Hi there, and glad you’ve managed to make some progress!

Would you be able to create a new project with a simple scene which replicates the prefabs duplicating and private message it to me? This will allow me to run my debugging tools to work out exactly what is happening :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sebasrez
Posts: 12
Joined: Fri Mar 04, 2022 1:57 pm

Re: Saving and loading prefab instances alongside pooling

Post by sebasrez »

So I recreated everything in a new project and it all worked! So I removed the es3 plugin in my project and reinstalled it and it worked, thanks so much for the help Joel!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving and loading prefab instances alongside pooling

Post by Joel »

Glad that's all working for you now :)

If you get a chance to leave a review on the Asset Store then that's always greatly appreciated, but no worries if you don't have time.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sebasrez
Posts: 12
Joined: Fri Mar 04, 2022 1:57 pm

Re: Saving and loading prefab instances alongside pooling

Post by sebasrez »

Left a review thank you!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving and loading prefab instances alongside pooling

Post by Joel »

Many thanks, let me know if you run into any other issues :)

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