Hi I have trouble getting ReorderableList to run in a custom Editor.
I followed this Tutorial: Unity: make your lists functional with ReorderableList
But I get an exception:
NullReferenceException: Object reference not set to an instance of an object UnityEditorInternal.ReorderableList.get_count () (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:371)
UnityEditorInternal.ReorderableList.GetListElementHeight () (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:424)
UnityEditorInternal.ReorderableList.DoLayoutList () (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:383)
Here is the relevant code I got so far:
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
public class MyClass : Monobehaviour
{
[SerializeField]
private List<object> _entries = new List<object>();
}
public class MyClassEditor : Editor
{
private SerializedProperty _entries;
private ReorderableList _entryList;
private void OnEnable()
{
_entries = serializedObject.FindProperty("_entries");
_entryList = new ReorderableList(serializedObject, _entries, false, false, false, false);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
_entryList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
The exception occures for the line _entryList.DoLayoutList();
.
So I made a brake point in VS and saw that it is always thrown for the count
property:
What am I doing wrong?