Page 1 of 1
How to store the ref of a ScriptableObject only?
Posted: Wed Dec 20, 2023 6:03 am
by silkmoon18
Hello,
I just found loading a SO also loads the data inside the SO. I am using SOs as info sources and don't want their data to be saved in runtime. How can I save the ref only?
Re: How to store the ref of a ScriptableObject only?
Posted: Wed Dec 20, 2023 9:27 am
by Joel
Hi there,
The Choosing what is saved guide describes how to choose which fields are saved:
https://docs.moodkie.com/easy-save-3/es ... -is-saved/
In your case you would mark all of the fields as ES3NonSerializable or deselect all of the fields in the Types window.
All the best,
Joel
Re: How to store the ref of a ScriptableObject only?
Posted: Wed Dec 20, 2023 12:12 pm
by silkmoon18
After some research, I found it was because I was storing them to a List<object> so they were not saved by ref. After changing it to List<UnityEngine.Object> they are now being saved by ref.
Is there another way to explicitly save an object by ref?
Re: How to store the ref of a ScriptableObject only?
Posted: Wed Dec 20, 2023 2:52 pm
by Joel
The only other way would be to get the reference ID and save and load that (though note that this is intentionally undocumented). You can get a reference ID using:
long id = ES3ReferenceMgr.Current.Get(object);
And get a reference from a reference ID using:
UnityEngine.Object obj - ES3ReferenceMgr.Current.Get(id);
All the best,
Joel