How do I create an array editor like the deault inspector?

Hi!

I want to use arrays in my custom editor.

// -- MyClass.cs --
using UnityEngine;
using System.Collections.Generic;

public class MyClass : MonoBehaviour {
	[SerializeField]
	public List<string> myList = new List<string>();
}

// -- MyClassEditor.cs --
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(MyClass))]
public class MyClassEditor : Editor {

    SerializedProperty myProperty;

    public void OnEnable() {
        myProperty = serializedObject.FindProperty("myList");
    }

    override public void OnInspectorGUI() {
        serializedObject.Update();

        EditorGUILayout.PropertyField(myProperty, new GUIContent("myList"), true);
        serializedObject.ApplyModifiedProperties();
    }
}

It seems to work fine, but I get the following error.

Using a SerializedProperty after the
object has been deleted is not
possible.
UnityEditor.EditorGUILayout:PropertyField(SerializedProperty, GUIContent, Boolean, GUILayoutOption[]) MyClassEditor:OnInspectorGUI() (at
Assets/Editor/MyClassEditor.cs:16)
UnityEditor.HandleUtility:EndHandles(EventType)

I know I could implement something myself, but I know it’s really hard to do right. I worry about the editors ability to handle prefab overrides, undo actions, element deletion through (cmd+delete) etc.

PropertyField actually doesn’t handle element deletion. The ultimate solution would have been if EditorGUILayout.PropertyField could just handle Arrays like the default inspector does.

I found the answer to this. I posted it over here.