Search code examples
c#unity-game-engineunity-editor

Cannot add a tooltip to appear when the mouse hovers to a unity EditorGUILayout.Popup()


I have a quite complex GUI in unity whit public override void OnInspectorGUI(). For all of my normal fieds I can add a tooltip with the header: Tooltip[("")] in the class itself. However, I need a dynamic dropdown list that needs to be updated with the number of elements of a list. I works great. Find the code of the custom editor script for the dropdown list:

        string[] options = new string[movParamsListSize];
        for (int i = 0; i < movParamsListSize; i++)
            options[i] = i.ToString();

        Rect r = EditorGUILayout.BeginHorizontal();
        movStepToMoveTo.intValue = EditorGUILayout.Popup("movementStepToMoveTo",
        movStepToMoveTo.intValue, options, EditorStyles.popup);
        EditorGUILayout.EndHorizontal();

Find also a screenShot:

enter image description here

My problem is that I tried with all the overloaded functions of the EditorGUILayout.Popup() function (image below from the metadata) and cannot figure out how to add a tooltip when the mouse hovers to this control.

enter image description here

Any help is much apprecciated. Many thanks


Solution

  • Use the overload of EditorGUILayout.Popup that takes a GUIContent instead:

    EditorGUILayout.Popup(new GUIContent("movementStepToMoveTo", "YOUR TOOLTIP HERE"), movStepToMoveTo.intValue, options);
    

    Btw the EditorStyles.Popup is redundant since this is the default for a Popup ;)

    and also HorizontalGroup is quite redundant here. You have only one control anyway.