-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Description:
I have a script extending the ScriptableObject class. One of the serialized fields of it is a class with the System.Serializable attribute. In this class, I use the ShowField attribute with a condition name corresponding to a bool property of the same class. I am using Unity 6.3.2 and EditorAttributes 3.0.0.
With this setup, clicking on my Scriptable Object instance throws an error (see log below) and prevents the serialized fields to be displayed.
Some notes:
- the bug occurs at least on Show / Hide / Enable / Disable Field attributes
- if I use ShowField("myProperty") in the scriptable object and not in a serialized class, there are no issue
- if I don't use a property, bu a field or a method instead, there are no issue (this is my current workaround)
Sample code to reproduce the error:
using EditorAttributes;
using UnityEngine;
[CreateAssetMenu(menuName = "TestScriptableObject", fileName = "TestScriptableObject")]
public class TestScriptableObject : ScriptableObject
{
[SerializeField, ShowField("MyProperty")]
private string myString;
public bool MyProperty => true;
[SerializeField]
private SerializedClass myNestedClass;
}
[System.Serializable]
public class SerializedClass
{
[SerializeField, ShowField("MyNestedProperty")]
private string myNestedString;
public bool MyNestedProperty => true;
}
Error log:
InvalidCastException: Specified cast is not valid.
System.Reflection.RuntimePropertyInfo.GetterAdapterFrame[T,R] (System.Reflection.RuntimePropertyInfo+Getter`2[T,R] getter, System.Object obj) (at <1eb9db207454431c84a47bcd81e79c37>:0)
System.Reflection.RuntimePropertyInfo.GetValue (System.Object obj, System.Object[] index) (at <1eb9db207454431c84a47bcd81e79c37>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimePropertyInfo.GetValue (System.Object obj, System.Object[] index) (at <1eb9db207454431c84a47bcd81e79c37>:0)
System.Reflection.PropertyInfo.GetValue (System.Object obj) (at <1eb9db207454431c84a47bcd81e79c37>:0)
EditorAttributes.Editor.Utility.ReflectionUtils.GetMemberInfoValue (System.Reflection.MemberInfo memberInfo, UnityEditor.SerializedProperty property) (at ./Library/PackageCache/com.v0lt.editor-attributes@bcdf9ed07431/Editor/Scripts/Utilities/ReflectionUtils.cs:458)
EditorAttributes.Editor.PropertyDrawerBase.GetConditionValue (System.Reflection.MemberInfo memberInfo, EditorAttributes.IConditionalAttribute conditionalAttribute, UnityEditor.SerializedProperty serializedProperty, UnityEngine.UIElements.HelpBox errorBox) (at ./Library/PackageCache/com.v0lt.editor-attributes@bcdf9ed07431/Editor/Scripts/Drawers/PropertyDrawerBase.cs:222)
EditorAttributes.Editor.ShowFieldDrawer+<>c__DisplayClass0_0.b__0 () (at ./Library/PackageCache/com.v0lt.editor-attributes@bcdf9ed07431/Editor/Scripts/Drawers/ConditionalAttributeDrawers/ShowFieldDrawer.cs:22)
EditorAttributes.Editor.PropertyDrawerBase.UpdateVisualElement (UnityEngine.UIElements.VisualElement visualElement, System.Action logicToUpdate, System.Int64 intervalMs) (at ./Library/PackageCache/com.v0lt.editor-attributes@bcdf9ed07431/Editor/Scripts/Drawers/PropertyDrawerBase.cs:295)
EditorAttributes.Editor.ShowFieldDrawer.CreatePropertyGUI (UnityEditor.SerializedProperty property) (at ./Library/PackageCache/com.v0lt.editor-attributes@bcdf9ed07431/Editor/Scripts/Drawers/ConditionalAttributeDrawers/ShowFieldDrawer.cs:20)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.SerializedProperty newProperty) (at :0)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at :0)
UnityEditor.UIElements.PropertyField.HandleEventBubbleUp (UnityEngine.UIElements.EventBase evt) (at :0)
UnityEngine.UIElements.EventDispatchUtilities.HandleEventAtTargetAndDefaultPhase (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target) (at <5c2380b11c444983ac3ffcbc73d04ba8>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.SendBindingEvent[TEventType] (TEventType evt, UnityEngine.UIElements.VisualElement target) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.Bind (UnityEngine.UIElements.VisualElement element) (at :0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation.Bind (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedObject obj) (at :0)
UnityEditor.UIElements.BindingExtensions.Bind (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedObject obj) (at :0)
UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.SerializedObject obj, UnityEditor.Editor editor, UnityEditor.UIElements.InspectorElement+DefaultInspectorFramework defaultInspectorFramework) (at :0)
UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor, UnityEditor.UIElements.InspectorElement+DefaultInspectorFramework defaultInspectorFramework) (at :0)
UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor) (at :0)
UnityEditor.UIElements.EditorElement.BuildInspectorElement () (at :0)
UnityEditor.UIElements.EditorElement.CreateInspectorElement () (at :0)
UnityEditor.EditorElementUpdater.CreateInspectorElementsForMilliseconds (System.Int64 targetMilliseconds) (at :0)
UnityEditor.PropertyEditor.Update () (at :0)
UnityEditor.HostView.SendUpdate () (at :0)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at :0)