Prefab changes variables back to previous version on play.

Discussion and help for Easy Save 3
Post Reply
BoBlond
Posts: 11
Joined: Thu Jul 29, 2021 10:54 am

Prefab changes variables back to previous version on play.

Post by BoBlond »

I have these Prefabs
Image

with this script on them
Image

The prefabs(tubasedcards) are referenced on another prefab in list form
Image

That list supplies my save prefab that save and loads lists for cards unlocked.

Image
Now when I, in the prefab (game no running) change a variable, it can be int, float or gameobject.
It will revert to previous setting when I press play?

How do I avoid that?

I tried adding the prefab to the refencemanager didn't work.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Prefab changes variables back to previous version on play.

Post by Joel »

Hi there,

Please could you show me the code you're using to load? Also what is the data you're saving? A List of GameObjects? If so, just to check, have you followed the Saving and Loading GameObjects guide?

https://docs.moodkie.com/easy-save-3/es ... s-prefabs/
Now when I, in the prefab (game no running) change a variable, it can be int, float or gameobject.
It will revert to previous setting when I press play?
This is expected behaviour, no? Because it will load the variables from the save data when you start the game, overriding whatever you've set outside of playmode.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BoBlond
Posts: 11
Joined: Thu Jul 29, 2021 10:54 am

Re: Prefab changes variables back to previous version on play.

Post by BoBlond »

Image
I just save a list of game objects.
so yeah maybe I just dont' understand but no I just want to save the link to gameobject, the variables on the card might change.
Last edited by BoBlond on Fri Aug 04, 2023 4:14 pm, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Prefab changes variables back to previous version on play.

Post by Joel »

Ah okay, I understand your issue now (this is quite different from the one in the thread you originally posted in).

By default collections of UnityEngine.Objects will be saved by reference and value. In your case you want to save them by value. To do this you can provide an ES3Settings object as a parameter when saving with it's referenceMode set to ES3.ReferenceMode.ByRef. I.e.

Code: Select all

var settings = new ES3Settings();
settings.referenceMode = ES3.ReferenceMode.ByRef;
ES3.Save("goReferences", gameObjectList, settings);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BoBlond
Posts: 11
Joined: Thu Jul 29, 2021 10:54 am

Re: Prefab changes variables back to previous version on play.

Post by BoBlond »

Thank you ! I'll try that now
Post Reply