No announcement yet.

[Solved] UMG OnHovered event for non-button controls

  • Filter
  • Time
  • Show
Clear All
new posts

    [Solved] UMG OnHovered event for non-button controls

    I'm creating a menu with a classic JRPG look, but for convenience, I also want it to be usable with the mouse.

    Click image for larger version  Name:	umgmenumissingonhovered.png Views:	1 Size:	164.8 KB ID:	1645216

    UMG Button controls have an 'OnHovered' event that works for me, but for some reason the 'OnHovered' event is not consistently implemented across controls.

    There are hover styles for the sliders and checkboxes, so both types of controls apparently know when the cursor is over them, but they don't expose this.

    What's the best workaround? Can I check the active style of a control? I've also seen a Q&A where a frame around the control was suggested for hover detection, but that seems hacky and brittle...
    Last edited by cygon; 08-11-2019, 10:39 AM. Reason: Added solved marker to indicate my problem is solved.

    The WidgetInteractionComponent has a field 'protected: UWidgetComponent* HoveredWidgetComponent' - it's accessible in Blueprint just fine, but it's protected on the C++ side.

    I thought maybe checking that checking that field once per tick, but I don't want to port my player controller to Blueprint or build some hard-to-maintain mix of Blueprint player controller derived from C++ player controller.

    Is there any way I could use the blueprint bindings from C++ to read the value stored in that field?

    Or could it be that the field isn't even meant to be accessed, with the UPROPERTY() macro only slapped onto it so UE's garbage collector can track the reference, in which case I'm still looking for another workaround


      Nevermind, I scanned the headers and there's a 'GetHoveredWidgetComponent()' method.

      However, it's only firing for the outermost control (i.e. if I have a Scroll Box with widget in them, GetHoveredWidgetComponent() will either return the scroll box or nullptr) and so far I couldn't figure out how to get the child widget that's actually under the mouse...


        Found a workaround that works for any UMG widget (or collection thereof):

        1. Create a new Widget Blueprint
        2. Put the Widget or Widgets on your new Blueprint
        3. Under 'Graph' add a "OnHovered" event dispatcher
        4. The Widget Blueprint will have an OnMouseEntered notification, add that to its EventGraph and make it call the OnHovered event