# Set/bind on mouse events for elements inside the Widget

**URL:** <https://forums.unrealengine.com/t/set-bind-on-mouse-events-for-elements-inside-the-widget/768993>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [February 12, 2023, 7:17am UTC](https://forums.unrealengine.com/t/set-bind-on-mouse-events-for-elements-inside-the-widget/768993 "2023-02-12T07:17:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Valentinvis](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/valentinvis/32/1008648_2.png) [@Valentinvis](https://forums.unrealengine.com/u/Valentinvis)\
**Post date:** [February 12, 2023, 9:06am UTC](https://forums.unrealengine.com/t/set-bind-on-mouse-events-for-elements-inside-the-widget/768993/3 "2023-02-12T09:06:08Z")

</div>

> [@Everynone](#):
>
> You did not miss anything.

Too bad. I was hoping this time I missed something. I come from a `Java/JavaFX` background and there each element from GUI have at one point in their parent/child hierarchy the same parent that contains all the mouse events as well as key press/released/typed events, and other more general events, and so you have access to them on each element and not just that scene/widget equivalent in Unreal Engine. Which in some situations are extremely useful.

> [@Everynone](#):
>
> And #2 is the way to go, #2 is the _only_ feasible way to go in order to achieve an interface that is maintainable, modular, flexible and scalable.

Yeah, that was the way I was going to go with, because even if you have a button with other elements in a widget created inside another widget, and you want that button to do something different for each instance of that child widget, you can simply get “child widget” → get button → Bind Event To on X.

> [@Everynone](#):
>
> Here’s a fantastic post addressesing lackluster UMG tunnelling / bubbling handling:

I had a few similar situation and I applied what I said above, but the difference is that in my case I only had 1 layer (main widget, and a child widget inside it with the button), and I could easily reach the button, and not had to call X gets to reach it.

A bit easier for me if I had a situation where I would have a widget inside another, inside another… which in the end has the button I would need to do something different each time, is that for each child widget I would create a function “Get Button” which would return the “Get Button” function from it’s child, until I reach the bottom child, where “Get Button” function would return the button itself. And so inside the main widget I could simply use “child widget” → Get Button → Bind Event to On Clicked.

A visual representation simplified:

Bottom widget that has the button itself:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/b/bbb982afa207924229595ff13b37228e0c449611.png)

1 layer/widget higher:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/d/56d87a96ebb480158b1815242b92f6e61116db37.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/c/cacce6a8095677314ab66f09ed9b00dafa279269.png)

2 layers/widgets higher:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/4/1/5415c5f9c9e4f2ad4a3295898e4120f5e869df7e.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/a/6/fa60da020e95d5ef61e0b696d84f5c4b73763850.png)

… how many layers/widgets higher you would have…

Top layer/widget:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/b/fdb8068e39d4058c85ec7cc1435ed0a04fbf2e3e.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/0/f/80f7badf8b2e494bd55f3ab95bbefe97092ab683.png)

> [@UMG Widget 'Event Drilling'](https://forums.unrealengine.com/t/umg-widget-event-drilling/768062/1):
>
> Now I had to create an event dispatcher on every level of the hierarchy so that I could pass that event onto the root component, where the side effects are located at.

Like he said it isn’t an elegant solution, but at least it is only tedious and not hard to implement. I’m the only one working on my project/game, and so, even if some things might be tedious, I will give in and make something like the hierarchy I said above, only to keep it going, and not get stuck in trying to get a better/elegant solution, which in the end, giving in, is kinda better because I’ll get on with the project, but on the other hand, maybe if I spend more time to find a better solution, it would save me time in the future?! Pros and cons situation.

---

_[View the full topic](https://forums.unrealengine.com/t/set-bind-on-mouse-events-for-elements-inside-the-widget/768993)._
