I’m having trouble getting GUI.tooltip to work well with GUI Windows and GUILayout. There are two issues:
- It seems that GUI.tooltip is only valid inside the Window’s GUI function, but I need to be able to show a tooltip that extends outside the boundaries of the Window.
- The tooltip needs to display even if the window is not focused.
Because I’m using GUILayout instead of GUI, I can’t check if the mouse position is inside the component’s rectangle.If anyone could show me how to get the below code working, it would be hugely appreciated!
using UnityEngine;
public class App : MonoBehaviour {
Rect win1Rect = new Rect(20, 20, 150, 150);
void OnGUI () {
GUILayout.BeginArea(win1Rect);
win1Rect = GUI.Window(0, win1Rect, DoWin1, "Win1");
GUILayout.EndArea();
if (GUI.tooltip != "") {
// Does not work because it's outside of DoWin1
GUI.Label(new Rect(0, 0, 100, 20), GUI.tooltip);
}
}
void DoWin1 (int windowId) {
GUILayout.BeginVertical();
GUILayout.Button(new GUIContent("Button", "Win1 tooltip"));
GUILayout.EndVertical();
}
}
Thanks for taking the time to respond. Unfortunately, this code didn't work for me (even after changing the label to use win1ToolTip instead of GUI.tooltip). However, what I ended up doing is only setting the value of win1ToolTip if onGUI is in the repaint frame: if (Event.current.type == EventType.Repaint). I guess now it will be a matter of creating a new window that holds this tooltip, and making sure it always renders on top of all other GUI components. Thanks for pointing me in the right direction.
– anon67279876Sorry for the typo ;) and yes, you're right you should only read the tooltip in repaint. I've edited my answer.
– Bunny83This just helped me a lot. It would've taken me ages to figure out why the tooltip was empty outside the window without this. :)
– CHPedersen