Setting widget text colour when button is hovered

Hi all!

I’m creating a UI which has different buttons, and the content of said buttons is just a text. Whenever the player hovers over a button, the colour of the text will change.

In order to achieve this, I’m using a function that looks like this:

It works as explained before, however there’s something I’m not quite happy with. I don’t want to create a unique function for every button that I have, I would like to create one that works for every button. Any ideas on how to do so following the same logic? In my head it would be easy if I could somehow query the engine: tell me which element am I hovering over, and use that to drive the branches that I have in place and the colour and opacity. However I don’t know how to do so.

Thanks in advance for your time!

Hi !
You can create a separate widget for your button, and add it dynamically to your main widget. So you can hold the logic inside, and create as many as you want.
From your main UI widget you can create and add child widget to any element like this :

If you need to differentiate your buttons, you can give them for example an “ID” variable and expose it on spawn.
Lemme know if wasn’t clear enough :slight_smile:

Edit : sorry that’s from my project but the first node is the “create widget” node, in which you can set the class you want.

Edit 2 : If you don’t need to add the buttons via blueprint you can also do it directly in the designer : you can search your button in the ‘user created’ tab and drag and drop it into your main widget.

Thanks for your comment leetnessdnb, I will take a look at that system you are describing. I’ve never done anything similar as to creating widgets inside of widgets, and for some reason I believe there must be a way to do what I was trying to do through my method, I just think I’m missing a particular blueprint node that would solve my issue haha.

Thanks a lot though, I will try your solution and see how it goes!