TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
148 stars 9 forks source link

Removing an element from a list may cause errors #38

Closed Gizzmicbob closed 2 months ago

Gizzmicbob commented 2 months ago

I have a list of structs that contains an enum and a vector. The enum has a ShowIf which shows or hides the Vector.

When removing an item from the list, it creates console errors.

ObjectDisposedException: SerializedProperty myStructs.Array.data[0].value has disappeared!
UnityEditor.SerializedProperty.get_propertyType () (at <3d611f181d2047d0a4666e5262482490>:0)
SaintsField.Editor.Drawers.VisibilityDrawers.VisibilityAttributeDrawer.ClassVisibility (UnityEditor.SerializedProperty property) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Drawers/VisibilityDrawers/VisibilityAttributeDrawer.cs:78)
SaintsField.Editor.Drawers.VisibilityDrawers.VisibilityAttributeDrawer.OnUpdateUIToolkit (UnityEditor.SerializedProperty property, SaintsField.ISaintsAttribute saintsAttribute, System.Int32 index, UnityEngine.UIElements.VisualElement container, System.Action`1[T] onValueChangedCallback, System.Reflection.FieldInfo info, System.Object _deprecated) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Drawers/VisibilityDrawers/VisibilityAttributeDrawer.cs:121)
SaintsField.Editor.Core.SaintsPropertyDrawer.OnUpdateUiToolKitInternal (UnityEditor.SerializedProperty property, UnityEngine.UIElements.VisualElement container, System.Object parent, System.Collections.Generic.IReadOnlyList`1[T] saintsPropertyDrawers, System.Action`1[T] onValueChangedCallback, System.Reflection.FieldInfo info) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Core/SaintsPropertyDrawer.cs:1955)
SaintsField.Editor.Core.SaintsPropertyDrawer+<>c__DisplayClass58_0.<OnUpdateUiToolKitInternal>b__0 () (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Core/SaintsPropertyDrawer.cs:1958)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <27c6e4ba3d774ae185a01cdc435b4022>:0)
InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)
UnityEditor.SerializedProperty.get_propertyType () (at <3d611f181d2047d0a4666e5262482490>:0)
SaintsField.Editor.Drawers.VisibilityDrawers.VisibilityAttributeDrawer.ClassVisibility (UnityEditor.SerializedProperty property) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Drawers/VisibilityDrawers/VisibilityAttributeDrawer.cs:78)
SaintsField.Editor.Drawers.VisibilityDrawers.VisibilityAttributeDrawer.OnUpdateUIToolkit (UnityEditor.SerializedProperty property, SaintsField.ISaintsAttribute saintsAttribute, System.Int32 index, UnityEngine.UIElements.VisualElement container, System.Action`1[T] onValueChangedCallback, System.Reflection.FieldInfo info, System.Object _deprecated) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Drawers/VisibilityDrawers/VisibilityAttributeDrawer.cs:121)
SaintsField.Editor.Core.SaintsPropertyDrawer.OnUpdateUiToolKitInternal (UnityEditor.SerializedProperty property, UnityEngine.UIElements.VisualElement container, System.Object parent, System.Collections.Generic.IReadOnlyList`1[T] saintsPropertyDrawers, System.Action`1[T] onValueChangedCallback, System.Reflection.FieldInfo info) (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Core/SaintsPropertyDrawer.cs:1955)
SaintsField.Editor.Core.SaintsPropertyDrawer+<>c__DisplayClass58_0.<OnUpdateUiToolKitInternal>b__0 () (at ./Library/PackageCache/today.comes.saintsfield@502055579a/Editor/Core/SaintsPropertyDrawer.cs:1958)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <546ade57fdec41a78409c727dbbd9e18>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <27c6e4ba3d774ae185a01cdc435b4022>:0)

Recreatable from Issue #29 test code

    public class Issue29 : MonoBehaviour
    {
        [Serializable]
        public enum Toggle
        {
            Off,
            On,
        }

        [Serializable]
        public struct MyStruct
        {
            public Toggle toggle;
            [ShowIf(nameof(toggle), Toggle.On)] public float value;
        }

        public MyStruct[] myStructs;
    }

Windows 10

Unity v2022.3.32f1

TylerTemp commented 2 months ago

@Gizzmicbob Hi,

I believe this issue is related to #34 and is fixed in 3.0.13

Could you check if your install is >= 3.0.13 ?

Gizzmicbob commented 2 months ago

I was on 3.0.11. Appears to be resolved after I updated - should've been the first thing I checked :)