LoadInto<GameObject>() ---- Am I Using It Wrong?

Discussion and help for Easy Save 3
Post Reply
threeguysgamestudio
Posts: 7
Joined: Thu Feb 14, 2019 10:52 pm

LoadInto<GameObject>() ---- Am I Using It Wrong?

Post by threeguysgamestudio »

When I use LoadInto<GameObject>(), things don't seem to be working properly.

1) Save<GameObject>()
2) Instantiate a GameObject myObject from Prefab
3) Call LoadInto<GameObject>(myObject)

Result:

myObject has been renamed, and assigned the correct properties from the saved object.

50% of the time there is an "Easy Save 3 Loaded GameObject" for each component that was supposed to be loaded into myObject.
50% of the time there is a single "Easy Save 3 Loaded GameObject" with all of the components that were supposed to be loaded into myObject.

Is it a problem that myObject already has the components (just without the correct data)? Does LoadInto require an empty GameObject? Or should it overwrite the existing components? If not, I need it to do so - how could I accomplish this?
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto<GameObject>() ---- Am I Using It Wrong?

Post by Joel »

Hi there,

You should not use ES3.LoadInto with GameObjects because GameObjects and Components are stored by reference, and the reference IDs will not exist in the instance you're loading into.

Instead you should use ES3.Load and follow the Saving and Loading Prefab Instances instructions on this page:
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
threeguysgamestudio
Posts: 7
Joined: Thu Feb 14, 2019 10:52 pm

Re: LoadInto<GameObject>() ---- Am I Using It Wrong?

Post by threeguysgamestudio »

I am running Unity 2018.3.5 (with the new Prefab structure), so the Prefab loading/saving stuff is all broken.

I really don't even need or want to use ref IDs because I need to be able to transport objects between scenes. All I want is for ES3 to find the component in the GameObject I pass it and overwrite it, or create a new component if one doesn't exist.

I don't mind hard-coding it in, but it's a little hard to follow all of the overloads and type casts.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto<GameObject>() ---- Am I Using It Wrong?

Post by Joel »

Hi there,

In that case you will need to save and load the Components individually using ES3.Save<YourComponentType>("yourKey", yourComponent) and ES3.LoadInto<YourComponentType>("yourKey", yourComponent).

It is not possible to save an entire GameObject without saving references because it would be impossible to know what data related to what Component.

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