Tooltips?

In short: How is it meant to implement Tooltips ? Is this even implemented? Or do we need to develop our own solution here?

The UI system doesn’t come with anything built-in for tooltips. You can do it yourself with a few simple scripts and setup:

  • Create a Tooltip script with simply a text string in it, that you put on every control that should have a tooltip.

  • Create a script that checks each frame what’s underneath the cursor (using the EventSystem). Query the Tooltip component of that object and if present get the text string value from it.

  • Update the visibility and text of a tooltip object in the UI accordingly (possibly the position too if it should follow the cursor). The UI object should be the last child under the Canvas to ensure it’s rendered last.

3 Likes

Thanks runevision :slight_smile:

It’s nevertheless a bit odd that there is no inbuild solution as with the old GUI.

I struggle with some problems here. It works. But it does not work very well.

Even with lateUpdate there is a massive lag behind the mouse position.
And i search for a way to impement a timer lag before the popup appears.

Means i am at the same situation now as with the old GUI before here. You CAN do everything by yourself. But it’s a bad out of the box experience. A experience that every user needs to repeat again now. And the lag behind the mouse position just yells for a inbuild solution that does not lag this horribly behind the mouse position.

May i request a inbuild solution? :slight_smile:

1 Like

I have created a video how to do a tooltip in an inventory system:

Maybe you have to watch the other videos aswell…Check them out.

2 Likes

Your solution looks a bit complicated, sorry. Nevertheless thanks for the video. Surely useful for some :slight_smile:

It’s not that i don’t know how to do it. I am just not this happy that i have to do it by myself. Tooltips is a standard behaviour of a UI. And the mouse lag issue is something that may be fixable with a deeper level access than through LateUpdate.

I have two simple scripts at the moment. This one comes at the tooltip object

#pragma strict

function LateUpdate () {

    transform.position.x=Input.mousePosition.x;
    transform.position.y=Input.mousePosition.y;

}

And this one comes at the button.

var mystring: String="Save the created mesh as Obj file";
var tooltip: GameObject;
var tooltiptextfield:UI.Text;

function pointerenter () {
    tooltip.SetActive(true);
    tooltiptextfield.text=mystring;
}

function pointerexit (){
    tooltip.SetActive(false);
}

Now drag the objects into the slots. Tooltip is the whole tooltip object. Tooltiptext the attached text component. And add two event triggers to each button. PointerEnter and PointerExit. And then call the corresponding loops with the event triggers.

And finally adjust the text at each button. Gives a individual tooltip at each button.

use this (4.6 UI) How to detect mouse over on button? - Questions & Answers - Unity Discussions
with your transform position

I’m hung up on the Tooltips as well. I have a solution that works rather well, it uses the EventSystems IPointerEnterHandler & IPointerExitHandler to detect when to display the Tooltip. I simply pass a string to the textbox inside my Tooltip Object. It even resizes perfectly now.

My issue is positioning the Tooltip. I tried using the localPosition of the RecTransform but it doesn’t work reliably if the object triggering the Tooltip is a child in a list.

Basically I have a container Listing Skill Objects and while Triggering is perfect, positioning is off. I can run my pointer over every skill being dynamically listed and a different description is displayed but I just cant get the tool tip to position over them. I even tried using a Vector 2 and Vector3 using the Input.mousePosition.x and Input.mousePosition.y coords.

The Z coordinate is a pretty frickin’ huge annoyance too. A tightly packed row of buttons with tooltips can be a problem because of the way depth-sorting works in the uGUI. I’d be fine with implementing them myself, since the actual display and object are easy, but the system needs a “frontmost” attribute.

1 Like

Working on something to solve this issue. My fingers have just started their work so its very early stages. I hope to have something soon.

2 Likes

Any updates on this? We’re getting some very odd bugs with 4.6 and wanted to see if there is more formal/supported execution for mouseover tooltips. We have a hacky solution but it has its problems.

So we don’t have a native solution for tooltips. That being said you can create your own as a text component, you can then attach a canvas to them and override the sorting. This will allow you to place the the tooltip on top of everything while using the hierarchy for positioning.

1 Like

Thank you, that helps a good amount. Is there any consistent way to then attach said canvas to the mouse cursor? I’ve been doing somewhat of a similar solution and approximating based on screen width, but I haven’t yet been able to find a consistent/proper way to link it to my mouse cursor location from there. Thanks for any help you can give.

1 Like

Same question as Tim_Warballoon.

No out of the box tooltip functionality for the new GUI? Ouch. I just started using it, and didn’t even think about it until I read this thread.

Guess they forgot about it :roll_eyes: Hopefully ways of doing a decent tooltip behavior will begin to surface after people get acquainted with the system. Or better yet, hopefully Unity devs add it into a future version of the GUI soon.

I’d have to sit down and figure out how to do it.

I personally ended in three little scripts and a somehow wicked object connection to solve the problem. A little timer to give some delay before the tooltip comes up, a script to set the tooltip component to the mouse when it is over a button. And the tooltip text that is attached at the buttons. The call for the tooltip gets called from the event trigger at the buttons then.

You can have a look at this project to see how the stuff is connected and set up in my solution. Just download the project file: 2014 – CuHe | Reiner's Tilesets

Would be of course much more elegant when there would be a inbuild solution :slight_smile:

2 Likes

Oh there will be a built in solution, just not yet :slight_smile:

2 Likes

That’s great :slight_smile:

Thanks for the answers! If anything it just makes us feel better - we thought the answer was obvious and we were just not executing it in the right way.