Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

SetDirty won't work on Nested List

$
0
0
Hi, usually I find my answer by myself but this time - after spending two days on this problem - I give up ^^ So I try to save a `List>` into a `ScriptableObject` but each time I make a change on it and restart Unity changes are lost/reset. I've already did it with a `List` and it worked perfectly, but this nested class got me. So here's the code: **- MyScriptableObject.cs** using UnityEngine; using System.Collections.Generic; public class MyScriptableObject : ScriptableObject { [System.Serializable] public class StringList: List { } [System.Serializable] public class Container : List { } [SerializeField] private Container cont; public void Fill () { // Fill with some random datas cont.Add(new StringList { "1A", "1B", "1C" }); cont.Add(new StringList { "2A", "2B", "2C" }); cont.Add(new StringList { "3A", "3B", "3C" }); } } **- MyCustomEditor.cs** using UnityEditor; using UnityEngine; [CustomEditor(typeof(MyScriptableObject))] public class MyCustomEditor : Editor { private MyScriptableObject script; void OnEnable () { script = target as MyScriptableObject; } public override void OnInspectorGUI () { DrawDefaultInspector(); if (GUILayout.Button("Fill")) { script.Fill(); EditorUtility.SetDirty(script); } } } Since I use `EditorUtility.SetDirty(script);` each time I change the asset I would have thought changes were saved but nothing. *Note:* When opening the .asset file after a change was made ( `Fill()` + `SetDirty()` + File > Save Project) I notice it doesn't contain my *random datas*. So basically changes are not saved into the .asset (i.e `SetDirty()` doesn't work) but the inspector keeps track of it until Unity restart (i.e Serialization works). Any idea how to figure this out?

Viewing all articles
Browse latest Browse all 827

Trending Articles