- Home /
Question by
vexe · Dec 28, 2013 at 06:15 AM ·
editorguilayoutserializedpropertycustom-editor
Custom editor struggle - "Invalid iteration - (You need to stop calling Next when it returns false)"
Been struggling a lot lately with custom editors and drawers. It seems like Unity doesn't give in easily, but yet insist on having a static non-resilient brain.
I got this error when I passed a a SerializedProperty
of a Vector3
value, into a EditorGUILayout.PropertyField
public abstract class FancyList : MonoBehaviour { }
public class FunnyLookingList : FancyList
{
[SerializeField] [HideInInspector]
private List<Vector3> list;
}
[CustomEditor(typeof(FancyList), true)]
public class FancyEditor : Editor
{
private SerializedProperty list;
private void OnEnable()
{
list = serializedObject.FindProperty("list");
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
list.Add(new Vector3(1, 1, 1));
EditorGUILayout.PropertyField(list.GetAt(0)); // <--
}
}
Where:
public static void Add(this SerializedProperty prop, Vector3 v)
{
prop.arraySize++;
prop.GetAt(prop.arraySize - 1).vector3Value = v;
}
public static SerializedProperty GetAt(this SerializedProperty prop, int i)
{
return prop.GetArrayElementAtIndex(i);
}
Any ideas?
Thanks.
Comment
DrawDefaultInspector might iterate through the SerializedProperty, leaving it at the last position. Have you tried caling
list.Reset();
after DrawDeafultInspector?