x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to detect mouse is over any Widget?

I have a main GUI widget and many child widgets and I set my input to InputModeGameAndUI. However whenever I click on a readonly-textbox (like the chatbox) or on the inventory, my character also receives this as input and starts walking.

It get's more complicated with widgets that are not rectangular (like a widget with a border for the background but the image is circular and etc) and some also have drag&drop functionality.

How is this best solved?

Product Version: UE 4.18
Tags:
more ▼

asked Nov 25 '17 at 03:01 PM in Blueprint Scripting

avatar image

Napoleonite
590 90 104 154

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

There is a node called Is Hovered, which returns a boolean with true if the current widget is hovered.

more ▼

answered Nov 25 '17 at 03:20 PM

avatar image

Unzkilled
310 3 7 10

avatar image Napoleonite Nov 25 '17 at 03:54 PM

So I have to add an OnHover() to every single (child-)widget (there are a lot)? And then it would also count as "onhover"when the mouse is over a transparent area (because non-rectangular UI's would then bug).

I don't think I can just use a boolean. I would have to have a list of userwidgets in the main-widget and when I hover over a widget, that widget is then added to the list of widgets. If the list is empty, that means that the player should receive input. Because what if widgets were to overlap each other and other exceptional cases? And when destroying widgets I also would have to check that list and if that specific widget is on it, remove it. Because I'm not sure if the OnMouseLeave() is then triggered. But I'm not sure.

No I sadly can't set the gamemode to UIOnly. I tried that before but it also blocks UI input from the playercontroller (in my case).

Is there no better alternative?

avatar image Napoleonite Nov 25 '17 at 03:56 PM

Maybe I could make a base class for all of my userwidgets and inherit from that. Then put this onhover/onmouseleave code in there so that every widget get's it. But still not.... ideal... (very dirty)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

What Unzkilled suggested would work just fine. Another alternative is to swtich to UI mode in onMouseEnter and back to Game and UI in onMouseLeave.

more ▼

answered Nov 25 '17 at 03:47 PM

avatar image

Everynone
14.8k 77 25 62

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

in my opinion "IsHovered" is a little buggy. look when bIsHovered flag is set:

 void SWidget::OnMouseEnter( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
 {
     bIsHovered = true;
 
     if (MouseEnterHandler.IsBound())
     {
         // A valid handler is assigned; let it handle the event.
         MouseEnterHandler.Execute(MyGeometry, MouseEvent);
     }
 }
 
 void SWidget::OnMouseLeave( const FPointerEvent& MouseEvent )
 {
     bIsHovered = false;
 
     if (MouseLeaveHandler.IsBound())
     {
         // A valid handler is assigned; let it handle the event.
         MouseLeaveHandler.Execute(MouseEvent);
     }
 }

this means that if you fire an "OnMouseEnter" and, for example, change your mode to "GameOnly", move the mouse outside widget area and then switch back to the "UIOnly" or "GameAndUI" modes, even if mouse is outside the widget, this still result as hovered. and there is no way to turn manually that "bIsHovered" flag back, because it is not exposed in blueprint...

more ▼

answered Feb 23 '18 at 01:01 PM

avatar image

lostwoods91
36 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question