Custom editor: How to initialise a new array element?

I’m trying to make a simple track editor that uses a Bezier Path to generate a 3d mesh for a friend’s racing game. The track data is an array of custom TrackDataPoint objects which store the position, tangent and other properties of each point on the track. Here is the TrackData and TrackDataPoint class code (I removed update functions of TrackData and all the “using” stuff to keep it compact here):

[System.Serializable]
public class TrackDataPoint : MonoBehaviour {
	Vector3 position = Vector3.zero;
	Vector3 tangentDir = Vector3.right;
	float tangentWeightIn = 1.0f;
	float tangentWeightOut = 1.0f;
}

[System.Serializable]
public class TrackData : MonoBehaviour {
	public TrackDataPoint[] points;
}

In my editor class, I am able to get a custom editor displaying, get a the list of points and get each point into a SerializedProperty object, however, I cannot figure out how to get the data into the list of TrackDataPoints stored in TrackData (points). I can add a new point using the small editor interface I made, but it is not initialized, so just appears as an empty space when I try to display it.

[CustomEditor(typeof(TrackData))]
public class TrackDataEditor : Editor {
	private SerializedObject trackData;
	private SerializedProperty points;
	
	void OnEnable () {
		trackData = new SerializedObject(target);
		points = trackData.FindProperty("points");
	}
	
	public override void OnInspectorGUI () {
		trackData.Update();
		//draw GUI for each point
		for (int i = 0; i < points.arraySize; ++i) {
			EditorGUILayout.BeginHorizontal();
    
			GUILayout.Label(i + ":", GUILayout.MaxWidth(20.0f));
			SerializedProperty dataPoint = points.GetArrayElementAtIndex(i);
			EditorGUILayout.PropertyField(dataPoint, true);
    
			EditorGUILayout.EndHorizontal();
		}
		
		EditorGUILayout.BeginHorizontal();
		if (GUILayout.Button("Add point")) {
		        points.array Size++;
                        // NOW WHAT!? :)    
		}
		EditorGUILayout.EndHorizontal();		

		trackData.ApplyModifiedProperties();
	}
}

How can I create a new TrackDataPoint and assign it to the empty array element from my editor script? If points happens to be a list of standard types, such as Vector3s, this happens automatically. As it is, I get new elements added to the array, but they are empty and display as a drop box for prefabs. If I remove the : MonoBehaviour from TrackDataPoint nothing shows up. Ideally I’d like to display a custom editor per point by having another editor for TrackDataPoint. Is this possible?

Here’s the working version using List<>:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]
public class TrackDataPoint : Object{
	public Vector3 position = Vector3.zero;
	public Vector3 tangentDir = Vector3.right;
	public float tangentWeightIn = 1.0f;
	public float tangentWeightOut = 1.0f;
}

[System.Serializable]
public class TrackData : MonoBehaviour {
	public List<TrackDataPoint> points;
}

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;

[CustomEditor(typeof(TrackData))]
public class TrackEditor : Editor {
	
private SerializedObject trackDataSO;
private TrackData myTrackData;
private List<bool> showTrackDataPoint;
	
void OnEnable () {
    trackDataSO = new SerializedObject(target);
    myTrackData = (TrackData)target;
}

public override void OnInspectorGUI () {
        trackDataSO.Update();
		
		EditorGUILayout.BeginVertical();

		int i = 0;
		
		foreach(TrackDataPoint tp in myTrackData.points){
			showTrackDataPoint _= EditorGUILayout.Foldout(showTrackDataPoint*,"Point #"+i);*_

_ if(showTrackDataPoint*){*_

* tp.position = EditorGUILayout.Vector3Field(“Position:”, tp.position);*
* tp.tangentDir = EditorGUILayout.Vector3Field(“TangentDir:”, tp.tangentDir);*
* tp.tangentWeightIn = EditorGUILayout.FloatField(“Tangent Weight In:”, tp.tangentWeightIn);*
* tp.tangentWeightOut = EditorGUILayout.FloatField(“Tangent Weight Out:”, tp.tangentWeightOut);*

* }*
* i++;*
* }*

* EditorGUILayout.EndVertical();*

* if (GUILayout.Button(“Add point”)) {*
* myTrackData.points.Add(new TrackDataPoint());*
* showTrackDataPoint.Add(false);*
* }*

* if(GUI.changed){*
* EditorUtility.SetDirty(target);*
* EditorUtility.SetDirty(myTrackData);*
* }*

trackDataSO.ApplyModifiedProperties();
*} *
}
The basic idea is to get a reference to the object you are editing by using
myTrackData = (TrackData)target;
That way you can do all the stuff you would normally do with arrays and such and don’t have to worry about SerializedProperty at all.
So you can add an element by adjusting the array length and adding the new point like you would do outside of the editor. Since you are working on the “target” object, only casted differently, all changes should automatically reflect in the editor.
Hope that points you into the right direction,
delstrega