Displaying multiple GUILayout button tooltips in a single GUILayout box?

Hello all,

So I just discovered how to display information when the mouse hovers above a GUILayout button in a custom inspector (Oh, big deal, right?). Lets say I have 4 GUILayout buttons in a row, and I would like to display their tolltips in a single GUI layout box, which is positioned below those buttons, when I hover the mouse over them one by one. Anyone have any suggestions on how this could be accomplished?

So far I am displaying the tooltip by using this:

EditorGUILayout.BeginHorizontal();
 if (GUILayout.Button(new GUIContent("Place object A", "Place selected object in a scene."), GUILayout.Height(30)))
     {
            //Place the object A code;
     }
 
  if (GUILayout.Button(new GUIContent("Remove object A", "Remove selected object"), GUILayout.Height(30)))
                         {
                             //Remove object A code;
                         }
 GUILayout.EndHorizontal();

Any input will be appreciated, thanks in advance!

Thanks for the tooltip code! It helped me. :slight_smile:

I know this post is old, but for the common label to show tooltip, if you mean Game view, I found an example.

If you are looking for the one for Inspector GUI, how about this? (I couldn’t find a better way…)

MyPlayer.cs (Attach this to GameObject)

using UnityEngine;

public class MyPlayer : MonoBehaviour
{

}

MyPlayerEditor.cs

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(MyPlayer))]
[CanEditMultipleObjects]
public class MyPlayerEditor : Editor
{
    void OnEnable()
    {
    }

    public override void OnInspectorGUI()
    {
        GUIContent btnA = new GUIContent("A");
        GUIContent btnB = new GUIContent("B");
        GUIStyle btnstyle = new GUIStyle(GUI.skin.button);
        btnstyle.margin = new RectOffset(10, 10, 10, 10); // left, right, top, bottom
        Rect btnARect = new Rect(btnstyle.margin.left, btnstyle.margin.top, 100, 30);
        Rect btnBRect = new Rect(btnstyle.margin.left + btnARect.width + btnstyle.margin.right, btnstyle.margin.top, 100, 30);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(btnA, btnstyle, GUILayout.Width(btnARect.width), GUILayout.Height(btnARect.height)))
        {
            //Place the Button A code;
        }
        if (GUILayout.Button(btnB, btnstyle, GUILayout.Width(btnBRect.width), GUILayout.Height(btnBRect.height)))
        {
            //Place the Button B code;
        }
        GUILayout.EndHorizontal();
        if (Event.current.mousePosition.x > btnARect.x && Event.current.mousePosition.x < btnARect.width &&
            Event.current.mousePosition.y > btnARect.y && Event.current.mousePosition.y < btnARect.height)
        {
            EditorGUILayout.LabelField("A tool tip");
        }
        else if (Event.current.mousePosition.x > btnBRect.x && Event.current.mousePosition.x < (btnBRect.x + btnBRect.width) &&
            Event.current.mousePosition.y > btnBRect.y && Event.current.mousePosition.y < btnBRect.height)
        {
            EditorGUILayout.LabelField("B tool tip");
        }
        else
        {
            EditorGUILayout.LabelField("");
        }
    }
}