List or Array of Custom Classes not saving into prefabs properly?

I have a class defined inside a component. It’s more or less just a struct of raw data:, i.e.

[ExecuteInEditMode]
class ListOfData : MonoBehavior 
{
    public class DataElement
    {
        public float stuff;
        public GameObject thing;
        //etc.
    }

    List<DataElement> mListOfDatas;



    void Update()
    {
    


        if (!Application.isPlaying)
        {
             mListOfDatas = mListOfDatas ?? new List<DataElement>();
        }
    }

}

I also have an editor script, changing the contents of mListOfDatas. Unfortunately, this data is not showing up in the component UI, and i’m guessing that only stuff shown in the UI will actually save. Is this the case, and is there a way to force this data to save to the prefab, or force it to display?

I think I’m getting to the limits of the prefab system, here.

First, only public variables or private variables with SerializeField attribute are serialized. Also you can only serialize arrays or lists of serializeable types. You can turn your DataElement class into a serialized type by adding the Serializable attribute

class ListOfData : MonoBehavior 
{
    [System.Serializable]
    public class DataElement
    {
        public float stuff;
        public GameObject thing;
        //etc.
    }
    [SerializeField]
    List<DataElement> mListOfDatas;

Add [Serializable] before your custom class declaration. Then the public members will be saved/editable like the ones in your MonoBehaviour.

i.e.

[Serializable]
public class DataElement
    {
...