Save and load data to and from different instances of a prefab in two scenes?

Discussion and help for Easy Save 3
Post Reply
Met
Posts: 3
Joined: Wed Feb 22, 2023 6:09 am

Save and load data to and from different instances of a prefab in two scenes?

Post by Met »

Hi, I'm a college student working on a final year project and I've just bought this package yesterday.

It's working great for the most part, but my main issue is as the title says. I have a prefab that holds the vast majority of my character data, things like money and a list of owned properties and things like that. This prefab exists in the Start scene and the Gameplay scene, the version in the Start scene has a Don't destroy on it, so it replaces the one in the Gameplay scene, which exists for serialization and the like.

My issue is that I need to save data from the Gameplay, or I suppose, DoNotDestroy scene and load it into the prefab in the Start scene. I've taken a look around and can't see a way to do this, though I am very unfamiliar with this package so any guidance would be fantastic. At the moment, anything that is changed during the start scene is properly saved and loaded into the start scene but not the gameplay scene, though it IS still saved. So I know that I do have the package set up correctly and its working to some degree, it just can't tell that I want it to save and load to prefabs directly I suppose?

Thanks for your help! :)
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save and load data to and from different instances of a prefab in two scenes?

Post by Joel »

Hi there, and thanks for getting in contact :)

Generally you would do this using the ES3.LoadInto method to tell Easy Save which instance you want to load the data into:
https://docs.moodkie.com/easy-save-3/es ... -loadinto/

This won't work however if your prefab has children as these need to be loaded by reference. In this case instead of saving the entire GameObject, you should save each individual Component and use ES3.LoadInto to load these into the Components on the prefab.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Met
Posts: 3
Joined: Wed Feb 22, 2023 6:09 am

Re: Save and load data to and from different instances of a prefab in two scenes?

Post by Met »

Thanks for the quick response!

My prefab is pretty complicated, there's a lot of nested prefabs inside of it which then in turn have a lot of prefabs inside of them. Is there any way to do this while still making use of the auto save/load functionality? I'm not really sure how to approach this at all.
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save and load data to and from different instances of a prefab in two scenes?

Post by Joel »

Hi there,

Auto Save is intended to load in the same scene as you saved in, as it relies on loading by reference. This isn't possible if you're loading in difference scenes or using DontDestroyOnLoad (as the object no longer exists in any persistent scene).

If taking the saving and loading Components approach using LoadInto, you would simply do the following:

Code: Select all

// To save Components
ES3.Save("myComponent", prefab.GetComponent<MyComponent>());
ES3.Save("myOtherComponent", prefab.GetComponent<MyOtherComponent>());
// etc
And the following to load:

Code: Select all

// To load Components
ES3.LoadInto("myComponent", prefab.GetComponent<MyComponent>());
ES3.LoadInto("myOtherComponent", prefab.GetComponent<MyOtherComponent>());
// etc
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Met
Posts: 3
Joined: Wed Feb 22, 2023 6:09 am

Re: Save and load data to and from different instances of a prefab in two scenes?

Post by Met »

Thank you! I'll give this a shot! :D
Post Reply