- Home /
Question by
oliver-jones · Dec 08, 2016 at 11:58 AM ·
listeditor-scriptingorderorderingpropertyfield
Editor Reorderable List - Properties
Hello,
I'm trying to build a very simple Reorderable List of type GameObject, but I can't get my head around it, in my script of MonoBehaviour, I have a list:
public List<GameObject> MyGameObjects = new List<GameObject>();
And within my Editor script (typeof above script):
private ReorderableList _list;
private void OnEnable() {
_list = new ReorderableList(
serializedObject,
serializedObject.FindProperty("MyGameObjects"),
true, true, true, true);
_list.drawElementCallback = (Rect rect,
int index,
bool isActive,
bool isFocused) => {
var element = _list.serializedProperty.GetArrayElementAtIndex(index);
EditorGUI.PropertyField(new Rect(rect.x,
rect.y, 60, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("GameObject"));
};
}
The problem lies within 'FindPropertyRelative' I believe. This gives me the error: Object reference not set to an instance of an object?
Thanks.
Comment
Best Answer
Answer by Adam-Mechtley · Dec 08, 2016 at 12:02 PM
Yes I'm not sure what you're trying to do, but it should just be element and not element.FindPropertyRelative("GameObject")
Ah okay thanks. How would I access a Component on that gameObject within this Editor too? I want to display a name from a Script attached.
You want SerializedProperty.objectReferenceValue. So something like this:
GameObject go = (GameObject)_list.serializedProperty.GetArrayElementAtIndex(index).objectReferenceValue;