Search Unity

New with UIElements in 2019 - How to draw default inspector

Discussion in 'Scripting' started by unity_hgBN-5fN8jGyWw, May 8, 2019.

  1. unity_hgBN-5fN8jGyWw

    unity_hgBN-5fN8jGyWw

    Joined:
    May 8, 2019
    Posts:
    2
    As title, I use Unity 2019.1 and try new UIElements. This feature can load UI from uxml. But how to draw default inspector? I tried DrawDefaultInspector() but it didn't work.

    Code (CSharp):
    1. public override VisualElement CreateInspectorGUI()
    2.     {
    3.         DrawDefaultInspector();
    4.         var root = new VisualElement();
    5.  
    6.         var uxml = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/Test.uxml");
    7.         var uss = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/Test.uss");
    8.  
    9.         uxml.CloneTree(root);
    10.         root.styleSheets.Add(uss);
    11.  
    12.         return root;
    13.     }
     
  2. matijas_05

    matijas_05

    Joined:
    May 8, 2017
    Posts:
    11
    I know you have probably found a solution to this already but I'm going to post this here for the other people who didn't.
    You just have to add this 'defaultInspector' VisualElement to the root.
    Code (CSharp):
    1. IMGUIContainer defaultInspector = new IMGUIContainer(() => DrawDefaultInspector());
     
    Last edited: Jun 17, 2019
    Menyus777, Baggers_, k4m4j1 and 4 others like this.