- Home /
ScriptableObject PropertyDrawer ArgumentOutOfRange Exception
I've been using a PropertyDrawer (from here) for displaying and editing ScriptableObjects in the editor. It works great, but there is an issue when the ScriptableObject being drawn has a reference to a collection of its own type. (There is no issue if it's a list of ScriptableObjects that is not the same type as the one being viewed).
public class Ability : ScriptableObject
{
public List<Ability> abilities;
}
As seen in the display below, if you ever try and interact with the list of an ability in the top level list, an ArguementOutOfRangeException gets thrown
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at :0) System.ThrowHelper.ThrowArgumentOutOfRangeException () (at :0) UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect, UnityEngine.Rect visibleRect) (at :0) UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at :0) UnityEditorInternal.ReorderableListWrapper.Draw (UnityEngine.GUIContent label, UnityEngine.Rect r, UnityEngine.Rect visibleArea, System.String tooltip, System.Boolean includeChildren) (at :0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at :0) UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at :0) UnityEditor.UIElements.InspectorElement+<>c_DisplayClass59_0.b_0 () (at :0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
Oddly enough, you can still add abilities to sub list, and it will properly render (as long as it isn't recursive), however the error will still be thrown, and the foldout buttons won't work.
Does anyone know about issues relating to recursive lists for property drawers and a way to fix this? I can see how what I want would be an issue if I made a recursive reference in the lists, but I am not sure why it would fail before that happens.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
1 out of 4 objects with the same script that reference the same transform list returning null? 1 Answer
How to add a reorderable list on CUSTOM EDITOR WINDOW? 0 Answers
Cannot include ScriptableObject in asset bundle in Unity 5 0 Answers
Animator Editor Window disappear when generate AnimatorController inside other asset 0 Answers