How to store the ref of a ScriptableObject only?

Discussion and help for Easy Save 3
Post Reply
silkmoon18
Posts: 13
Joined: Sun Oct 01, 2023 11:04 am

How to store the ref of a ScriptableObject only?

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to store the ref of a ScriptableObject only?

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
silkmoon18
Posts: 13
Joined: Sun Oct 01, 2023 11:04 am

Re: How to store the ref of a ScriptableObject only?

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to store the ref of a ScriptableObject only?

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply