Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Custom inspector for List does not work

Discussion in 'Visual Scripting' started by tomi-trescak, Feb 23, 2021.

  1. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    78
    Hi, I have following objects:

    Code (CSharp):
    1. [IncludeInSettings(true)]
    2. [Inspectable]
    3. public classTrialImage
    4. {
    5.     [Inspectable]
    6.     public Sprite asset;
    7.     [Inspectable]
    8.     public bool interact;
    9. }
    10.  
    11. [IncludeInSettings(true)]
    12. [Inspectable]
    13. public class TrialImageGroup
    14. {
    15.     [Inspectable]
    16.     public int imageCount;
    17.     [Inspectable]
    18.     public List<TrialImage> images;
    19. }
    And I have a following property drawer

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [CustomPropertyDrawer(typeof(TrialImage))]
    5. public class TrialImageDrawer : PropertyDrawer
    6. {
    7.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    8.     {
    9.      
    10.        EditorGUI.BeginProperty(position, label, property);
    11.        Rect newPosition = new Rect(position.x, position.y, position.width, position.height);
    12.  
    13.        SerializedProperty item = property.FindPropertyRelative("sprite");
    14.        EditorGUI.PropertyField(newPosition, item, new GUIContent("sprite"));
    15.  
    16.        EditorGUI.EndProperty();
    17.     }
    18. }
    I generate custom property drawers, but I receieve a following error:

    Code (CSharp):
    1. InvalidOperationException: Failed to find property 'PropertyProvider_TrialImage.item'.
    2. Ludiq.SerializedPropertyUtility.FindPropertyOrFail (UnityEditor.SerializedObject serializedObject, System.String path) (at Ludiq.Core.Editor/SerializedProperties/SerializedPropertyUtility.cs:120)
    3. Ludiq.SerializedPropertyUtility.CreateTemporaryProperty (System.Type type) (at Ludiq.Core.Editor/SerializedProperties/SerializedPropertyUtility.cs:73)
    4. Ludiq.CustomPropertyDrawerInspector.Initialize () (at Ludiq.Core.Editor/Inspection/Special/CustomPropertyDrawerInspector.cs:15)
    5. Ludiq.InspectorProvider.CreateDecorator (System.Type decoratorType, Ludiq.Metadata metadata) (at Ludiq.Core.Editor/Inspection/InspectorProvider.cs:19)
    6. Ludiq.SingleDecoratorProvider`3[TDecorated,TDecorator,TAttribute].CreateDecorator (TDecorated decorated) (at Ludiq.Core.Editor/Decorators/SingleDecoratorProvider.cs:42)
    7. Ludiq.SingleDecoratorProvider`3[TDecorated,TDecorator,TAttribute].GetDecorator (TDecorated decorated) (at Ludiq.Core.Editor/Decorators/SingleDecoratorProvider.cs:253)
    8. Ludiq.XInspectorProvider.Inspector (Ludiq.Metadata metadata) (at Ludiq.Core.Editor/Inspection/InspectorProvider.cs:174)
    9. Ludiq.LudiqGUI.GetInspectorHeight (Ludiq.Inspector parentInspector, Ludiq.Metadata metadata, System.Single width, UnityEngine.GUIContent label) (at Ludiq.Core.Editor/Interface/LudiqGUI.cs:76)
    10. Ludiq.MetadataListAdaptor.GetItemHeight (System.Single width, System.Int32 index) (at Ludiq.Core.Editor/Inspection/MetadataListAdaptor.cs:229)
    11. Ludiq.MetadataCollectionAdaptor.GetItemHeight (System.Int32 index) (at Ludiq.Core.Editor/Inspection/MetadataCollectionAdaptor.cs:105)
    12. Ludiq.ReorderableList.ReorderableListControl.CalculateListHeight (Ludiq.ReorderableList.IReorderableListAdaptor adaptor) (at Ludiq.Core.Editor/Dependencies/ReorderableList/ReorderableListControl.cs:2118)
    13. Ludiq.MetadataCollectionAdaptor.GetHeight (System.Single width, UnityEngine.GUIContent label) (at Ludiq.Core.Editor/Inspection/MetadataCollectionAdaptor.cs:148)
    14. Ludiq.ListInspector.GetHeight (System.Single width, UnityEngine.GUIContent label) (at Ludiq.Core.Editor/Inspection/Special/ListInspector.cs:16)
    15. Ludiq.Inspector.GetCachedHeight (System.Single width, UnityEngine.GUIContent label, Ludiq.Inspector parentInspector) (at Ludiq.Core.Editor/Inspection/Inspector.cs:192)
    Any idea where this erro is coming from?
     
    Last edited: Feb 23, 2021