ES3: Question saving a list of object active states

Discussion and help for Easy Save 3
Alatriste
Posts: 6
Joined: Mon May 08, 2017 7:41 am

Re: ES3: Question saving a list of object active states

Post by Alatriste »

Sent. Thanks.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3: Question saving a list of object active states

Post by Joel »

Hi there,

I understand what is happening. In your case the individual script will not work.

However, I've created a manager for you which will work for you. Simply attach the following script to an object which is always active in your scene (i.e. the Main Camera), and drag the GameObjects you want to save the active state of into it's gameObjects array.

As this uses Easy Save's reference manager, you may need to press the Refresh References button on the ES3ReferenceMgr component of the Easy Save 3 Manager to get it to recognise new references in your scene, as you currently have Auto Update References disabled.

Also don't forget to delete the old SaveActive scripts.

All the best,
Joel
Attachments
SaveActiveStates.cs
(865 Bytes) Downloaded 270 times
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Alatriste
Posts: 6
Joined: Mon May 08, 2017 7:41 am

Re: ES3: Question saving a list of object active states

Post by Alatriste »

Awesome! Thanks a lot Joel, I'll implement it this weekend! :)
Alatriste
Posts: 6
Joined: Mon May 08, 2017 7:41 am

Re: ES3: Question saving a list of object active states

Post by Alatriste »

Hi Joel,

I tried your script in my test scene, and if I understood correctly, your script basically saves the latest status of the object (enable or disable) automatically.

However, when I have to reload the scene I'm getting the following error "MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it." I guess because you thought that in my game I'm not using the "Load Scene" action, which I do.

Basically what I try to achieve here is that if the player saves the game at any point, the status of some gameObjects in the scene (enable or disable) has to be saved as well. Then, if the player reloads that slot saved, those objects should load the status they were at the moment the game was saved. Does it make sense? I could do this with bool variables, but I'd like to know if there is a more efficient way.

Thanks!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3: Question saving a list of object active states

Post by Joel »

Hi there,

Would you be able to PM me another project replicating what is happening so I can modify the script for your case? I'm not fully sure I understand what is causing the error.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
cbassing
Posts: 1
Joined: Fri Jun 11, 2021 7:57 pm

Re: ES3: Question saving a list of object active states

Post by cbassing »

Hello,

So the SaveActive.cs seems to work when saving the active status of the gameObject that is already enabled at runtime. However, When that scene is reloaded from another scene the gameObjects are still disabled. I would imagine this is because they are disabled from the beginning and when the scene is reloaded, they are disabled at Start and are unable to run on Awake and execute this.gameObject.SetActive(ES3.Load<bool>(guid));. Is there a better way to load active status on objects that are disabled at runtime or are enabled using an event?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3: Question saving a list of object active states

Post by Joel »

Hi there,

Because the scripts will be disabled when you first load the app, none of their methods will be called.

In this case you would instead need to make a manager script which finds all of the objects which you want to save the active state of, put all of the active states into a bool array and then save this. Then when loading, you would load the bool array and enable/disable each GameObject as appropriate.

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