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


I want to use arrays in my custom editor.

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

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

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

public class MyClassEditor : Editor {

    SerializedProperty myProperty;

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

    override public void OnInspectorGUI() {

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

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

Using a SerializedProperty after the
object has been deleted is not
UnityEditor.EditorGUILayout:PropertyField(SerializedProperty, GUIContent, Boolean, GUILayoutOption[]) MyClassEditor:OnInspectorGUI() (at

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.