Page 1 of 1

Save ScriptableObject fields?

Posted: Wed Sep 07, 2022 4:33 pm
by gill_82
Firstly,

great program; has been very useful to me.

But, I've tried Saving/Loading SOs that contain a SO field, and that field data doesn't Save/Load. Is it possible to do?


Eg:
public void MySO : ScriptableObject
{

public OtherSO otherSO;

}

MySO instance saves, but otherSO data is null on Load.

Re: Save ScriptableObject fields?

Posted: Thu Sep 08, 2022 7:24 am
by Joel
Hi there,

Fields of UnityEngine.Object types (such as ScriptableObjects) are saved by reference, so this indicates that a reference to that ScriptableObject no longer exists (perhaps because it's created at runtime). Are you getting a warning in console saying that a reference is missing?

In this case you should also have a separate save call to save any ScriptableObjects which might need to be loaded by reference. For example every time you create an instance of a ScriptableObject you could add it to a List and save this. And then before loading anything which may reference these ScriptableObjects, load this List.

All the best,
Joel

Re: Save ScriptableObject fields?

Posted: Fri Sep 09, 2022 2:27 pm
by gill_82
Ok, no problem.

Thanks