Search Unity

Adding item to List with multiple objects selected throws error when accessing SerializedProperty

Discussion in 'Immediate Mode GUI (IMGUI)' started by keenanwoodall, Feb 1, 2019.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    559
    I think this problem may be a little too confusing to explain in text, so I made a video to show the problem and explain everything I've tried. Hopefully someone is familiar with this error. I've been stuck on this error for a couple days and haven't found a single answer online or through my troubleshooting.


    Here's the error:

    Code (CSharp):
    1. InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)
    2. UnityEditor.SerializedProperty.Verify (UnityEditor.SerializedProperty+VerifyFlags verifyFlags) (at C:/buildslave/unity/build/Editor/Mono/SerializedProperty.bindings.cs:330)
    3. UnityEditor.SerializedProperty.FindPropertyRelativeInternal (System.String propertyPath) (at C:/buildslave/unity/build/Editor/Mono/SerializedProperty.bindings.cs:1320)
    4. UnityEditor.SerializedProperty.FindPropertyRelative (System.String relativePropertyPath) (at C:/buildslave/unity/build/Editor/Mono/SerializedProperty.bindings.cs:204)
     
  2. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    559
    Somehow the object is not being registered as dirty so serializedObject.Update isn't doing anything.

    It's still not completely clear what causes this issue. From what I can tell, it happens when you don't change a field through a SerializedProperty while having multiple objects selected. If you don't use the SerializedProperty, the SerializedObject isn't marked as dirt so calling serializedObject.Update doesn't do anything. You need to call serializedObject.SetIsDifferentCacheDirty() before calling Update which will mark it dirty and in-turn make Update work properly.