Custom inspector for scriptable object resets object

I have a scriptable object that holds a list of objects, and I have a custom inspector for it. When I select the object in the project view it shows the custom inspector however when I make any changes to the custom editor (even just adding an empty line somewhere and saving) it resets the object to default instead of just changing the controls in the inspector.

Here’s the inspector code:

public class NonBranchingConversationEditor : Editor
	public override void OnInspectorGUI()
		NonBranchingConversation t = target as NonBranchingConversation;

		GUILayout.Label("Node Count: " + t.dialogueNodes.Count);

		if (GUILayout.Button("Add New Node"))
			t.dialogueNodes.Add(new NonBranchingDialogueNode());

		for (int i = 0; i < t.dialogueNodes.Count; i++)
			GUILayout.Label("Node " + (i+1));

			t.dialogueNodes_.text = EditorGUILayout.TextField("Text", t.dialogueNodes*.text);*_

* Seperator();*
* }*

* EditorUtility.SetDirty(t);*
* }*

* void Seperator()*
* {*
* GUILayout.Label(“-----------------------------------”);*
* }*
And here’s the scriptable object:
public class NonBranchingConversation : ScriptableObject
* public List dialogueNodes = new List();*
If anyone can help with this it would be greatly appreciated.
EDIT: After a bit more goggling, I found something that said to nest one of the classes within the other, but after trying both of mine nested within each other it still doesn’t work. Any other suggestions?

Maybe its too late, but use this line of the code, after you changed something in your object:


just in case someone else comes across this problem in the future, where by changing the editor script code removes the existing items within the scriptable object.

PAEveson was correct the fix is adding [System.Serializable], but you need to add it to the class(es) the scriptable object is storing, not the scriptable object script itself.