Search Unity

CustomPropertyDrawer for List problems

Discussion in 'UI Toolkit' started by Araj, Apr 3, 2020.

  1. Araj

    Araj

    Joined:
    Jan 3, 2013
    Posts:
    27
    Hi,

    I'm trying to create a CustomPropertyDrawer for Lists and so far, nothing works. Here is what I've tried so far:
    - Create an Attribute to tag the List
    - Create a CustomPropertyDrawer for that Attribute
    - Fail miserably :)

    Code (CSharp):
    1.  
    2. [MyCoolList]
    3. public List<string> theList = new List<string>();
    4.  
    In the CustomPropertyDrawer I tried to put a simple Debug.Log to see if at least the drawer is created, but the message never appears.
    Code (CSharp):
    1.         public override VisualElement CreatePropertyGUI(SerializedProperty property)
    2.         {
    3.            
    4.             Debug.Log(property);
    5.         }
    However, if instead of creating a List, I do something like this:
    Code (CSharp):
    1.         public class WhateverList : List<string> {}
    2.         [MyCoolList]
    3.         public WhateverList theList = new WhateverList();
    I see the Debug.Log message. That lead's me to think that right now, the PropertyDrawer for Lists is hardcoded and can't be overridden.

    I really don't want to create a new class every time I want to draw a list with my custom drawer.
    Can you help me?

    Thanks!
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This workflow isn't yet supported in UI Toolkit (formally UIElements). It's a temporary limitation but I can't say when it will be fixed right now.
     
  3. Araj

    Araj

    Joined:
    Jan 3, 2013
    Posts:
    27
    Oh, good to know, I was going crazy trying things :)

    Will try to combine UI Toolkit with IMGUI to overcome this temporal limitation.

    Thanks a lot @uDamian!