- Home /
Problem is not reproducible or outdated
ReorderableList Custom Editor Count -> NullReferenceExeception
Hi I have trouble getting ReorderableList to run in a custom Editor.
I followed this Tutorial: http://va.lent.in/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?
Answer by YoloJero · May 02, 2018 at 08:01 AM
Hi never mind _entries
was null in the MyClassEditor
since object
is not serializeable in Unity. I changed it now to use a custom class.
Follow this Question
Related Questions
How can I use a GUIStyle in a Custom Editor which is set within that Custom Editor? 1 Answer
Why is my propertydrawer being automatically disabled? 1 Answer
Serializedproperty assignment 2 Answers
Should EditorGUILayout.PropertyField work with serializable classes? 1 Answer
How to create a new SerializedProperty? 0 Answers