Rollover mouse/gun aimer to show widget BP

Hi Guys,

Hopefully, someone could help me out with this.

I’m looking to show a pop-up text (widget BP) by rolling the mouse/gun aimer over an object.
What I have got so far, its a pop-up text by clicking the middle button of the mouse. I really have no clue how to do it on roll-over.

I appreciate if anybody could guide me a bit.

Thanks in advance

Hi, you could use a timer and check every “time” wether or not your mouse cursor hits your target.

And I would create the widget only once and save it into a variable, and then add it to the viewport when necessary (else you will create numerous widgets) and remove it from the viewport when not necessary. And if you want to check for a hit under your mouse, theres a node called “Get Hit Result Under Cursor by Channel” (you may have to deactivate “Context Sensitive” for the search)

Hi, thanks for the reply.
I have tried but I still don’t understand how to do it. Sorry, I’m quite new with blueprints.

Would it be possible for you to explain a bit more or show me how to actually link these nodes?

thanks in advance

Sure, create a new character blueprint (right click in the conten browser → Blueprint Class → Character). Add a camera (in viewport “+ Add Component” → type camera). Then build these nodes in the event graphs of the character.

In the graph “Show Mouse Cursor” is set to true so you will see the cursor. “Dummy Widget Own” should be your text widget. That’s the widget I used.

Its important that you set “Is Variable” to True in your text (this will enable you to change the text in your blueprint).

This setup will spawn the popup text on any actor that you’re mouse hovers over. The location were it will be spawned will be the location of the component of the actor you’re hover the mouse over (projected onto the screen).

And I forgot, you must then set this character class as default pawn class, so you start with this character (in your main editor window Settings → World Settings → set the default pawn class to this character class). As an alternitive you could add these nodes into the character your currently use (haven’t tried that but should work as well).

Hi, What kind of variables are “pop up text”, “last hit component” & “text block 169” in the BP character?
also whats the node that comes from hit component and “last hit component” that goes to the 2nd branch condition.

What’s it after set text node?

Thank you very much for your help

pop up text → the widget you want to display

last hit component → primitive component

text block 169 → your text variable in the widget

You have a event “Check for Rollover” that performs a linetrace to your mouse position and displays a widget over the component the mouse is hovering. This event is called every “Time” (that’s what the “set timer by event” is for, right now it is called every 0,1 sec). To get the object under the mouse cursor theres a node “Get Hit Result Under Cursor by Channel”. The setup only continues when there was a hit (the first branch). Then it checks if the “Hit Component” is the same as the Last Hit Component (if it is then the widget is already displayed and there is no need to continue), if it is, it does not continue (so “Last Hit Component” is of type “Primitive Component”), thats the second branch. If its a new Hit Component it sets that as the Last Hit Component. Then you want to display a widget (the text) over this component. The widget is created at the Begin Play Event and is saved into the “Popup Text” variable (so the type of this is the widget you want to display, btw. you can right click on the Return Value and select Promote to Variable). “Add To Viewport” adds the widget to the viewport so you can actually see it (“Remove from Parent” removes the widget from the viewport). Right now the widget only contains a text that is set to be a variable (second image widget.png). The name of this variable is “Text Block 169” (you can rename it in the widget (second image left side) to whatever you want). Then you set the text in the “SetText (Text)” node (the text you enter there is the text that get actually displayed). Then you want to position your widget on the screen (in the current setup it gets displayed over the hit component). You only have the world location of the hit component but you need a screen position, thats what the node “Project World to Screen” does.

thanks very much, it’s working perfectly now.