InvalidOperationException when accessing SerializedProperty in CustomPropertyDrawer

Issue #24 resolved
Ivan Wang
created an issue

I have a custom property drawer for a custom System.Serializable struct IntVector2.

IntVector2: https://pastebin.com/7xXFGFbX

IntVector2Drawer: https://pastebin.com/nmfkC1M0

However, when rendering the editor for a class with the field IntVector2, the following error occurs: https://pastebin.com/c9i0wxAb

From my best guess, it looks like the SerializedProperty has already been cycled through (via Next) and can't be used in the OnGUI method anymore.

In case this isn't enough to reproduce the bug: the class containing IntVector2 (call it A) extends an abstract class B, which is serialized in a list as

[OdinSerialize]
public List<B> testList;

Error occurs in Unity v5.5.0f3.

Comments (4)

  1. Tor Esa Vestergaard

    I've been unable to reproduce this bug on the latest patch (0.9.0.4), and changes were introduced in 0.9.0.3 that may very well haved fixed this issue. Could you please try upgrading from your current version (0.9.0.2) to 0.9.0.3 or 0.9.0.4, and tell me if the error persists?

  2. Bjarke Elias Clauson-Kaas Ørrild

    Also just a quick tip in case you didn't know. Writing drawers using Odin makes your life a little easier 😋 No need to return the height of a property, you can use GUILayout, and you also don't need to think too much about undo, Odin also takes care of that. And multi-selection also works in many simple cases out of the box using the entry.SmartValue

    Here is an example of your IntVector2 drawer using Odin.

    [InspectorDrawer]
    public class IntVector2Drawer : OdinValueDrawer<IntVector2>
    {
        protected override void DrawPropertyLayout(IPropertyValueEntry<IntVector2> entry, GUIContent label, params GUILayoutOption[] options)
        {
            Vector2 v2 = SirenixEditorFields.Vector2Field(label, new Vector2(entry.SmartValue.x, entry.SmartValue.y));
            entry.SmartValue = new IntVector2((int)v2.x, (int)v2.y);
        }
    }
    
  3. Log in to comment