- Home /
Save Data from Editor Script, Serialize Nested Class List
I have an Editor script that manipulates data from a Component script in the scene. However, when I save the scene and exit Unity, all of the data in the Component script is lost. How can we save data that persists after closing Unity from an Editor script?
Edit:
I believe the problem I'm having has to do with serializing nested classes:
[System.Serialize]
public class OuterClass() {
List<InnerClass> someList = new List<InnerClass>();
}
public class InnerClass() {
public int someInt;
}
Unity is having trouble retaining the List of InnerClass objects. How can you properly serialize this example?
Answer by coastwise · Oct 30, 2012 at 02:12 PM
public class OuterClass : MonoBehaviour {
[SerializeField] // this is required for non-public fields
List<InnerClass> someList = new List<InnerClass>();
}
[System.Serializable]
public class InnerClass {
public int someInt;
}
If `OuterClass` is not a MonoBehaviour but rather included in one (which might be why you've indicated it to be Serializable), then you'll probably need make it inherit from `ScriptableObject`. Please refer to the Serialization Best Practices Megapost.
Your answer
Follow this Question
Related Questions
object list not serializing 2 Answers
Editor extension, How do I Serialized nested class? 0 Answers
Custom editor toggles doesn't save 0 Answers