overlapping tooltips,.... why?

Hello guys,

I have a problem in understanding the Tooltips thing. I have a set of buttons and I want a tooltip to pop up for each of them. The problem I have is that for the second button, the tooltip shows up very nicely, but when I’m on the first button, BOTH the tooltips show up and overlap each other. Any help would be appreciated. Thanks! :smile:
This is the code:

if (GUI.Button(Rect(sx,sy,32, 32),GUIContent("","New/Reset Scene"), "New")) {
	}
	GUI.Label(Rect(sx,sy+30,50,50), GUI.tooltip,"tooltip");
	
	if (GUI.Button( Rect(sx + 40, sy, 32, 32), GUIContent("","Set iso-view"), "iso")){
	}	
	GUI.Label(Rect(sx + 40, sy+30, 32, 32),GUI.tooltip,"tooltip");

569445--20264--$GUI.JPG

This is the solution i’ve found: the global variable GUI.tooltip has to be initialized an cleaned everytime a new GUIContent and so a new tooltip is crated. I would like to underline the fat that NOTHING in the user/programming manual is mentioned about that.

var newContent = GUIContent("","New/Reseat Scene");
    GUI.tooltip = "";
	if (GUI.Button(Rect(sx,sy,32, 32),newContent, "New")) {
	}
	GUI.Label(Rect(sx,sy+30,50,50), GUI.tooltip,"tooltip");
	
	GUI.tooltip = "";
	if (GUI.Button( Rect(sx + 40, sy, 32, 32), GUIContent("","Set iso-view"), "iso")){
	}	
	GUI.Label(Rect(sx + 40, sy+30, 32, 32),GUI.tooltip,"tooltip");

Wow, Giancamati!

You saved me a ton of head scratching. Thanks for posting this!

Zaffer

This is how I handle my tool tips.

 // If you have many GUI Elements and you want the tool tip to only select over one.. You can
 // Have a counter such as i..
               int i = 0;
               GUI.Label(new Rect(x, y, 100, 20), new GUIContent("Resilence ", "hoverStat"+i) , perkBar);
		if(GUI.tooltip.Equals("hoverStat"+i))
		{
			activateToolTip = true;
			strName = "Resilence";
			strDescription = charInfo.resilenceDescription;
		}
                i++
                GUI.Label(new Rect(x, y, 100, 20), new GUIContent("Embrace ", "hoverStat"+i) , perkBar);
		if(GUI.tooltip.Equals("hoverStat"+i))
		{
			activateToolTip = true;
			strName = "Embrace";
			strDescription = charInfo.embraceDescription;
		}

// Then we call our Tooltip Method.
               if(activateToolTip)
		{
			SpecialMoves t = new SpecialMoves();  // Just a data type I made that holds string name and Description.
			t.specialName = strName;
			t.description = strDescription;
			specialMoveToolTip = t;
			toolTipIndex = i;
			showToolTip = true;
		}
		else if(GUI.tooltip.Equals(""))   //We have no item being moused over. 
		{
			specialMoveToolTip = null;
			showToolTip = false;
			GUI.tooltip = "";
			activateToolTip = false;
		}
// In the Class variable we have a holder for that Data.
SpecialMoves specialMoveToolTip = new SpecialMoves();  // If this is null tooltip will ignore it.

public void ShowToolTipWindow(int id)
	{
		if(toolTipIndex > -1)
		{
			GUI.depth = 1;
			if(toolTipObject != null)
				GUI.Label(new Rect(15,25,200, 200), toolTipObject.description, perkBar);
			else if(specialMoveToolTip != null)
				GUI.Label(new Rect(15,25,200, 200), specialMoveToolTip.description, perkBar);
			GUI.BringWindowToFront(id);
		}
	}

//Then we have our tooltip window that is display.. I'm omitting stuff however.
void ShowToolTip()
	{
		//Tool Tip will be displayed when we mouse over the selected item.
		if(showToolTip)
		{
			GUI.depth = 1;
			if(toolTipIndex > -1)
			{
				tooltipPos = new Vector2(Input.mousePosition.x+15, Screen.height-Input.mousePosition.y);
				
				if(tooltipPos.x > Screen.width-toolTipSize.x)
					tooltipPos.x = (Input.mousePosition.x-(toolTipSize.x) );
				
				toolTipWindow = new Rect(tooltipPos.x, tooltipPos.y, toolTipSize.x, toolTipSize.y);
				if(toolTipObject != null)
					toolTipWindow = GUI.Window(255, toolTipWindow, ShowToolTipWindow, toolTipObject.name, toolTipWindowStyle);
				else if(specialMoveToolTip != null)
					toolTipWindow = GUI.Window(255, toolTipWindow, ShowToolTipWindow, specialMoveToolTip.specialName, toolTipWindowStyle);
			}
		}		
	}

ShowToolTip(); is just being called in the OnGUI method. But its never ran unless the boolean for it is true.

Probably seems more complicated. But if you use alot of Tooltips its very handy to reuse.