Question by
keel-210 · Feb 01, 2017 at 07:42 PM ·
editoreditor-scripting
Unity5-serializedObject.FindProperty("listname") for ReorderableList doesn't work...
I'm writing CustomEditor for ReorderableList of list.But Unity says NullReferenceException. I find that serializedObject.FindProperty("listname") is null. This is my code.
Element of List
public class TestClass
{
[UnityEngine.SerializeField]
public TestEnum com,seccom;
}
public enum TestEnum
{
up,
down,
right,
left,
}
List
using System.Collections.Generic;
using UnityEngine;
public class ListTest : MonoBehaviour
{
[SerializeField]
public List<TestClass> Listtest = new List<TestClass>();
}
ListEditor
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CanEditMultipleObjects]
[CustomEditor(typeof(ListTest))]
public class ListTestEditor : Editor
{
private ReorderableList RL;
private SerializedProperty ListProp;
private void OnEnable()
{
//↓doesn't work
ListProp = serializedObject.FindProperty("Listtest");
Debug.Log(ListProp);
//↑return null
RL = new ReorderableList(serializedObject, ListProp);
RL.drawElementCallback = (rect, index, isActive, isFocused) =>
{
var element = ListProp.GetArrayElementAtIndex(index);
EditorGUI.PropertyField(rect, element);
};
}
public override void OnInspectorGUI()
{
serializedObject.Update();
RL.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
Sorry for my poor English.
Comment
Best Answer
Answer by Adam-Mechtley · Feb 01, 2017 at 07:45 PM
TestClass
needs to be marked with System.Serializable
Your answer
Follow this Question
Related Questions
EDITOR HOW TO GET A TEXT FILE OBJECT OR INSTANCE ID TO FOCUS THE PROJECT WINDOW ON IT 1 Answer
Error BCW0012 'UnityEngine.Application.LoadLevel(String)' is obsolete. Use SceneManager.LoadScene 1 Answer
Editor - Selecting multiple active objects in project view 0 Answers
Running code once on editor start? 0 Answers