Saving ScriptableObjects by asset reference

Discussion and help for Easy Save 3
Post Reply
Caffeen
Posts: 3
Joined: Thu Mar 07, 2019 8:32 pm

Saving ScriptableObjects by asset reference

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

Re: Saving ScriptableObjects by asset reference

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Caffeen
Posts: 3
Joined: Thu Mar 07, 2019 8:32 pm

Re: Saving ScriptableObjects by asset reference

Post 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!
Post Reply