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?


I believe the problem I’m having has to do with serializing nested classes:

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?

public class OuterClass : MonoBehaviour {
[SerializeField] // this is required for non-public fields
List someList = new List();

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.