Search Unity

Getting "No GUI Implemented" with CustomPropertyDrawer (2020.1), even in official example

Discussion in 'UI Toolkit' started by MostHated, Sep 5, 2020.

  1. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Heya,
    I keep getting "No GUI Implemented" when trying to use CustomPropertyDrawer. I kept reducing down what I was trying to do more and more until it was just a class with two strings in it and still get it, so I decided to try out the official example and get the same thing there too.

    I could not find much on this, but what little things I could find said implementing a default drawer which I did as well:
    Code (CSharp):
    1.     [CustomEditor(typeof(Object), true, isFallback = true)]
    2.     [CanEditMultipleObjects]
    3.     public class DefaultEditorDrawer : UnityEditor.Editor
    4.     {
    5.         public override VisualElement CreateInspectorGUI()
    6.         {
    7.             var root = new VisualElement();
    8.  
    9.             var property = serializedObject.GetIterator();
    10.             if (property.NextVisible(true)) // Expand first child.
    11.             {
    12.                 do
    13.                 {
    14.                     var field = new PropertyField(property) {name = "PropertyField:" + property.propertyPath};
    15.  
    16.                     if (property.propertyPath == "m_Script" && serializedObject.targetObject != null)
    17.                     {
    18.                         field.SetEnabled(false);
    19.                     }
    20.  
    21.                     root.Add(field);
    22.                 } while (property.NextVisible(false));
    23.             }
    24.  
    25.             return root;
    26.         }
    27.     }

    So far all things result in the following:



    The only way I was able to get it to work was using something of a
    proxy object but then it only is visible when looking at the ScriptableObject directly, or when looking at the editor window.




    Am I missing something? I can't seem to figure out what I might be missing.
     
  2. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    I had some issues with this too. It seems like the UI elements version will only be used if the rest of your editor UI is using UI elements. Since the inspector by default is using OnGUI you would still need to override the OnGUI method in your property drawer or you'll have to make your component editor in UI elements.
    Unity dev, feel free to correct me if I'm wrong.
     
  3. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Yeah, it looked like that was the reason that I needed to have the "DefaultDrawer", which I did/do have. I am also only using UIElements for everything I have been making, so I am not sure what else would need to be done.
     
  4. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    I might have it worked out, but maybe there is a better way?

    It looks like not only does there need to be an editor for what you are trying to draw, but you have to make a separate custom editor for *each component* which is doing to contain and display it?

    So if I have this DefaultEditor class:
    Code (CSharp):
    1.   [CustomEditor(typeof(Object), true, isFallback = true)]
    2.     [CanEditMultipleObjects]
    3.     public class DefaultEditorDrawer : UnityEditor.Editor
    4.     {
    5.         public override VisualElement CreateInspectorGUI()
    6.         {
    7.             var root = new VisualElement();
    8.  
    9.             var property = serializedObject.GetIterator();
    10.             if (property.NextVisible(true)) // Expand first child.
    11.             {
    12.                 do
    13.                 {
    14.                     var field = new PropertyField(property) {name = "PropertyField:" + property.propertyPath};
    15.  
    16.                     if (property.propertyPath == "m_Script" && serializedObject.targetObject != null)
    17.                     {
    18.                         field.SetEnabled(false);
    19.                     }
    20.  
    21.                     root.Add(field);
    22.                 } while (property.NextVisible(false));
    23.             }
    24.  
    25.             return root;
    26.         }
    27.     }

    Then let's say I have 3 components which are going to display a custom property, for every component in which I want to have a custom property drawn, I have to basically create a running file in an editor folder and add every class to it like this?

    Code (CSharp):
    1.     [CustomEditor(typeof(TestComponent))]
    2.     public class TestComponentEditor : DefaultEditorDrawer
    3.     {
    4.     }  
    5.  
    6.     [CustomEditor(typeof(Test2Component))]
    7.     public class Test2ComponentEditor : DefaultEditorDrawer
    8.     {
    9.     }  
    10.  
    11.     [CustomEditor(typeof(Test3Component))]
    12.     public class Test3ComponentEditor: DefaultEditorDrawer
    13.     {
    14.     }
     
  5. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    For now this is the case. The editor does not use UITK for default inspectors/property drawers yet. So if you have any MonoBehaviour or serialized class that is displayed in anything using UITK, it needs to have a custom inspector/drawer.
     
    MostHated likes this.
  6. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Yeah, I have just continued on as I did in my post above and things have been just fine, for the most part. So all is well.