Hey everyone,
I’ve been trying to get a ScriptableObject that’s tied to a MonoBehaviour to serialize into the scene without writing it out as an asset. It seems like it’s never serialized into the scene no matter what I do. I just wanted to see if it’s just not how it’s supposed to be used or if I’m missing something. Here’s a basic rundown of how it’s setup:
MonoBehaviour class that holds the ScriptableObject
public class TestObj : MonoBehaviour {
public TestSObj testSObj;
}
ScriptableObject class
[Serializable]
public class TestSObj : ScriptableObject {
public string name;
}
CustomEditor for Monobehaviour
[CustomEditor(typeof(TestObj))]
public class TestObjEditor : Editor {
TestObj testObj;
public override void OnInspectorGUI() {
testObj = (TestObj)target;
DrawDefaultInspector();
if (GUILayout.Button("Create")) { Create(); }
}
void Create() {
testObj.testSObj = ScriptableObject.CreateInstance<TestSObj>();
EditorUtility.SetDirty(testObj);
}
}
I apologize in advance for the terrible class names. Any insight into this issue would be greatly appreciated, thanks!