I noticed that they have events for when the widget is pressed or clicked, but not for hovered. I want to be able to change the buttons color whent he widget is being hovered (which works fine for mouse). but i want to be able to do this for a gamepad as well. I found a function that Checks if it is hovered, but not to set the value.
This is probs a bit late but for any one also looking for this as I was. I’ve just figured out how to do it, you have to get the button you’re trying to manipulate, get its current stytel and feed it to the set method. Just swap the normal and hovered state around. So normal set in set method is equal to hovered state in get method.
Please please elaborate…I’ve been searching for ages and it seems like you have the answer…if you can, please post a picture of your blueprint
This is how I did it. This is on the event constructed/begin play. I’m grabbing the default button and setting it’s style as my “DefaultButton” style, then splitting the out pin into a struct, and creating a second button style called “HoverButton” which I’m then feeding the “hovered” style portion from the default button style into the default portion on the new button style. This is giving me two style variables I can easily plug in whenever I need to swap the styles out.
Hope that helped! Thanks to Angel1630 for giving me the original idea. Worked perfect!
I attempted it this way but it did not work the way I intended, i believe this has something to do with a prior tutorial I went through in regards to using keyboard focus and switching the style of buttons, anyway this is what i was going for
None of the solutions using style worked for me. I couldn’t get the changes to reflect on the buttons. What I ended up doing was setting all the button state tints to White
and then just changing the color using SetBackgroundColor
. I unified the mouse and game pad code by overriding the OnHovered
and OnPressed
events for the buttons and changing the color there in the same manner as with the gamepad path. I noticed that all of these applied a “tint” to the button which made me think color component multiplication so setting every other value to white and then just setting the background color had the desired effect.
I know that this is an old topic, but given how hard it is to come by functioning stuff regarding those things, I would like to add a more dynamic solution.
This one works regardless of your button style (e.g. you have different styled buttons in your menu).
Its only the bare foundation though:
Notes:
-
ForEachLoopWithBreak is just a thing I do, to stop cycling an array where I already found the one button that can be highlighted, its not needed and just optimization stuff. (currently unplugged)
-
“Is In Viewport” is an option (But I would recommend using an Event or tie this into your setup for showing the widgets) to only run this when its in viewport, which will be good for performance if you have a lot of buttons etc.
-
you can easily turn this into an actual function, and even use one for all your widgets, instead of putting one inside each of your widgets. (since I assume that many here have more than one widget for their menu.)
=================
PS: yes, I am aware that there is some fancy new work in progress keybinding etc. thingy in UE5 (that can be used to also do this), but I dont touch things that have “experimental” next to it, which parts of it have in 5.3… therefore I am still running my almost 10 years old keybinding solution/setup now. (if it works, it works, eh?)
PS2: you can probably get away without the “is valid”, but I dont like getting “None” messages in log.