How to save/load a list of instances (GameObject) in an ES3ComponentType?

Discussion and help for Easy Save 3
Post Reply
gabrieljacintho
Posts: 7
Joined: Wed Apr 03, 2024 12:17 pm

How to save/load a list of instances (GameObject) in an ES3ComponentType?

Post by gabrieljacintho »

Hello, :D

I tried to create an ES3ComponentType that would save a list of GameObjects (instances) and load it, but I noticed that after I close and open the game again the list is loaded with null spaces.

And yes, prefabs have the ES3Prefab component.

Is it possible to do what I'm trying to do? My goal is to load an ObjectFactory that is inside an instance instantiated by another ObjectFactory.

Just for explanation purposes, I have an ObjectFactory of breakable crates that when broken, instantiate a GameObject.

Thank you for your attention,
Gabriel Jacintho
Last edited by gabrieljacintho on Wed Apr 03, 2024 6:38 pm, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save/load a list of instances (GameObject) in an ES3ComponentType?

Post by Joel »

Hi there,

If you have a field which is a List<GameObject> you should just be able to navigate to your Component in the Easy Save 3 > Types window and select that field, which will automatically create the ES3Type. You shouldn't need to create your own ES3ComponentType.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
gabrieljacintho
Posts: 7
Joined: Wed Apr 03, 2024 12:17 pm

Re: How to save/load a list of instances (GameObject) in an ES3ComponentType?

Post by gabrieljacintho »

Hello Joel, nice to meet you and thanks for your fast response!

I did exactly what you said and the script is still receiving a list with null items :cry:
ES3UserType_Spawner.cs
(1.79 KiB) Downloaded 20 times
When I save the game and load again it works, but if a close the game and reopen, the load return a list with null items.

Note: The game objects are in the DontDestroyOnLoad scene, but I tested in the game scene and also don't worked.

Do you have any suggestion about how to fix it?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save/load a list of instances (GameObject) in an ES3ComponentType?

Post by Joel »

Hi there,

Fields of UnityEngine.Object type (or Collections of UnityEngine.Object type) will be saved by reference, not by value.

In your case you would either need to save your List of GameObjects using a separate ES3.Save call to ensure that they're saved by value and reference, or you would need to provide an ES3Settings object which specifies that you want fields to be saved by reference and value. I.e.

Code: Select all

var settings = new ES3Settings();
settings.memberReferenceMode = ES3.ReferenceMode.ByRefAndValue;
ES3.Save("key", yourSpawner, settings);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
gabrieljacintho
Posts: 7
Joined: Wed Apr 03, 2024 12:17 pm

Re: How to save/load a list of instances (GameObject) in an ES3ComponentType?

Post by gabrieljacintho »

Okay, thank you for the explanation! My goal was to make this without a save key, but I made with ES3.Save and it worked! :D
Post Reply