Method arguments are incompatible exception using ValidateInput in structs

Issue #528 resolved
krnd created an issue

ValidateInput attribute throws exception when using it on a struct field. Classes work perfectly find and OnValueChanged work on both. I found another issue (#297) concerning structs and ValidateInput - but I do not know whether they are related in some way.

Environment

  • Windows 10
  • Unity 2019.1.0f2
  • Odin 2.0.17.0

Exception Trace

ArgumentException: method arguments are incompatible
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
Sirenix.OdinInspector.Editor.Drawers.ValidateInputAttributeDrawer`1+InnerDrawer`1[T,TParent].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, Sirenix.OdinInspector.ValidateInputAttribute attribute, UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/ValidateInputAttributeDrawer.cs:105)
Sirenix.OdinInspector.Editor.Drawers.ValidateInputAttributeDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/ValidateInputAttributeDrawer.cs:37)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:306)
Sirenix.OdinInspector.Editor.Drawers.PrimitiveValueConflictDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PrimitiveValueConflictDrawer.cs:58)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:306)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:313)
Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:176)
Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:540)
Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
Odin Property Path: aStruct.interalValue
Odin Drawer Chain:
> PropertyContextMenuDrawer<float>
> PrimitiveValueConflictDrawer<float>
> ValidateInputAttributeDrawer<float>
> SingleDrawer
> CompositeDrawer.
UnityEngine.Debug:LogException(Exception)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:590)
Sirenix.OdinInspector.Editor.Drawers.CompositeDrawer:DrawPropertyLayout(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/CompositeDrawer.cs:73)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:306)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1:DrawPropertyLayout(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:313)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:176)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:540)
Sirenix.OdinInspector.Editor.InspectorUtilities:DrawPropertiesInTree(PropertyTree) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Misc/InspectorUtilities.cs:380)
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:275)
Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:94)
Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:234)
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at C:/Projects/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:86)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Test Code

public class __mono : MonoBehaviour {
    [SerializeField]
    public __struct structMember;
    [SerializeField]
    public __class classMember;
}

[Serializable]
public struct __struct {
    [SerializeField,
        ValidateInput(nameof(OnValidate)),
        OnValueChanged(nameof(OnValueChanged))]
    public int value;

    public bool OnValidate(int _) {
        Debug.Log($"{this.GetType().Name}::{nameof(OnValidate)}");
        return true;
    }
    public void OnValueChanged()
        => Debug.Log($"{this.GetType().Name}::{nameof(OnValueChanged)}");
}

[Serializable]
public class __class {
    [SerializeField,
        ValidateInput(nameof(OnValidate)),
        OnValueChanged(nameof(OnValueChanged))]
    public int value;

    public bool OnValidate(int _) {
        Debug.Log($"{this.GetType().Name}::{nameof(OnValidate)}");
        return true;
    }
    public void OnValueChanged()
        => Debug.Log($"{this.GetType().Name}::{nameof(OnValueChanged)}");
}

Comments (7)

  1. Log in to comment