Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Enum not using custom property drawer

Discussion in 'Visual Scripting' started by bubicus, Nov 11, 2022.

  1. bubicus

    bubicus

    Joined:
    Apr 18, 2013
    Posts:
    8
    I am having a problem getting a custom property drawer to work on an enum we'll call "MyEnum".

    I created a property drawer following Unity's instructions. (https://docs.unity3d.com/Packages/com.unity.visualscripting@1.7/manual/vs-create-custom-drawer.html), and it works fine in the editor's component inspector on a component that has a MyEnum field. MyEnum is Serializable, but not Inspectable since it is an enum.

    When I create a Visual Scripting node that has a ValueInput expecting a value of type MyEnum, it doesn't use the property drawer. It outputs the raw information from the enum. I already tried the Project Settings->Custom Inspector Properties->Generate button and also the Project Settings->Node Library->Regenerate Nodes button after adding MyEnum to Project Settings->Type Options, and the property drawer still doesn't execute.

    To verify, I added a Debug.Log statement to the property drawer's OnGUI method, and the output happens in the editor's component inspector but doesn't happen in the Visual Scripting node. How does one connect a property drawer to Visual Scripting correctly?

    Here is a barebones version of the property drawer. It does nothing but output to the debug log. Debug output appears on a component but does not appear on a VS node.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5. using UnityEngine.UIElements;
    6. using static Foo.FooTeam;
    7.  
    8. [CustomPropertyDrawer(typeof(MyEnum))]
    9. public class CustomEnumPropertyDrawer : PropertyDrawer
    10. {
    11.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    12.     {
    13.         Debug.Log("[CustomEnumPropertyDrawer] OnGUI");
    14.         base.OnGUI(position, property, label);
    15.     }
    16.  
    17.     public override VisualElement CreatePropertyGUI(SerializedProperty property)
    18.     {
    19.         Debug.Log("[CustomEnumPropertyDrawer] CreatePropertyGUI");
    20.         return base.CreatePropertyGUI(property);
    21.     }
    22. }
    23.  
     
    Last edited: Nov 11, 2022
  2. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    Have you solved that problem?
     
    Veuch and Opeth001 like this.
  3. Veuch

    Veuch

    Joined:
    Feb 4, 2020
    Posts:
    5
    I have the same issue.

    Weird thing is, it worked at some point in the past, and it doesn't anymore.

    I get the "No inspector for '[type]'" warning
     
  4. Veuch

    Veuch

    Joined:
    Feb 4, 2020
    Posts:
    5
    Okay, so I just remember posting here and not posting back after finding the solution (rude, I know, sorry)

    Anyways, the answer was pretty stupid. I just needed to click the Button
    Project Settings > Visual Scripting > Generate
    . It's under the "Custom Inspector Properties" label