Page 1 of 1

Saving ScriptableObjects by asset reference

Posted: Tue Sep 24, 2019 12:00 am
by Caffeen
Can you save ScriptableObjects by asset reference, without instantiating them? I haven't had any issue saving/loading Instantiated SOs, but any time I save a class with a reference to an SO asset, it always nulls out on reload.

Is what I'm attempting even possible?

Thanks in advance

Re: Saving ScriptableObjects by asset reference

Posted: Tue Sep 24, 2019 4:59 pm
by Joel
Hi there,

This is indeed possible, but you will need to make sure that your scene references that SO (i.e. there's a variable in your scene which contains a reference to that SO at build time), otherwise it won't be added to the reference manager.

You might also want to press the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager after doing this to ensure that it's detected.

A basic test script which demonstrates this is as follows:
using UnityEngine;

public class ScriptWithSO : MonoBehaviour
{
	public ScriptableObject so;

    // Start is called before the first frame update
    void Start()
    {
        ES3.Save<ScriptWithSO>("so", this);
		so = null;
		ES3.LoadInto<ScriptWithSO>("so", this);
    }
}
All the best,
Joel

Re: Saving ScriptableObjects by asset reference

Posted: Wed Sep 25, 2019 9:17 pm
by Caffeen
Gotcha, so either way it needs to already exist in the scene via an SO "database" component that already exists.

Thanks for your quick response!