Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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

Discussion in 'Extensions & OnGUI' started by keenanwoodall, Feb 1, 2019.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    545
    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:
    545
    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.