Search Unity

UIToolkit-based inspector for StateMachineBehaviour

Discussion in 'UI Toolkit' started by mbussidk, Apr 9, 2020.

  1. mbussidk

    mbussidk

    Joined:
    May 9, 2017
    Posts:
    67
    Hi all, is it possible to create an inspector for a StateMachineBehaviour using UIElements/UIToolkit?
    I'm trying to create one (in Unity 2019.3.7f1) and in my custom inspector the CreateInspectorGUI() is never invoked:

    Code (CSharp):
    1.  
    2.     [CustomEditor(typeof(MyBehaviour), true)]
    3.     public class MyBehaviourInspector : Editor
    4.     {
    5.         public override VisualElement CreateInspectorGUI()
    6.         {
    7.             Debug.Log("MyBehaviourInspector");
    8.             var visualTree = Resources.Load<VisualTreeAsset>("EadonSpellAttackInspector");
    9.             var uxmlVE = visualTree.CloneTree();
    10.             uxmlVE.styleSheets.Add(Resources.Load<StyleSheet>("Eadon"));
    11.             return uxmlVE;
    12.         }
    13.  
    14. /*
    15.         public override void OnInspectorGUI()
    16.         {
    17.             GUILayout.BeginVertical("Test", "window", GUILayout.ExpandWidth(true));
    18.             GUILayout.BeginHorizontal();
    19.             EditorGUILayout.LabelField("TEST", EditorStyles.boldLabel);
    20.             GUILayout.EndHorizontal();
    21.             GUILayout.EndVertical();
    22.         }
    23. */
    24.     }
    25.  
    If I comment the method and uncomment the OnInspectorGUI() method, then I can see my custom inspector.
    Anyone else facing the same problem?
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Hello,

    Unfortunately this is not possible today because the StateMachineBehaviour is handled in a very specific way by animation inspectors. Currently this part of Unity is IMGUI-only.

    This is the kind we're hoping to fix in the long term but for now you'll have to stick to OnInspectorGUI().
     
  3. mbussidk

    mbussidk

    Joined:
    May 9, 2017
    Posts:
    67
    Hi @antoine-unity thanks for the clarification. I’ll stick to IMGUI. At least I know I was not doing something wrong...
     
  4. jhipster

    jhipster

    Joined:
    Feb 14, 2020
    Posts:
    1
    2 years later - is there any update on this? Just attempted (and failed) to make a custom inspector for a Statemachinebehaviour using UI Toolkit. Hopefully this is on the roadmap by now :D
     
    Last edited: Jun 8, 2022
  5. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    I am forwarding this request to the Animation team, will report back if it's planned.
     
    jhipster likes this.
  6. Josh093

    Josh093

    Joined:
    Aug 28, 2020
    Posts:
    1
    Is this still an issue?
     
  7. rawna

    rawna

    Joined:
    Aug 13, 2015
    Posts:
    35
    I would like to know if this in development, or if we can expect it soon.
    If not, is there any workaround without recreating all my custom drawers in IMGUI.
     
  8. rawna

    rawna

    Joined:
    Aug 13, 2015
    Posts:
    35
    I found one workaround for the issue

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. class InspectSMBInUIToolkit {
    4.     [MenuItem("CONTEXT/StateMachineBehaviour/Inspect in UIToolkit", priority = 100)]
    5.     internal static void WatchScriptableObject(MenuCommand command) {
    6.         Selection.activeObject = command.context;
    7.     }
    8. }
    This will allow you to right click a SMB header and choose 'Inspect in UIToolkit', which will allow UIToolkit based custom editors and property drawers

    I still would prefer an official solution, as this requires an extra step for modifying each SMB, but it's better than nothing