I have very recently started using Unreal. coming from Unity, and I happened to ask myself if the way I was reasoning during my first blueprint attempts were actually reasonable… or if there’s something I’m missing (of course not just one thing).
That said, today I wanted to change the color of a text nested in a button in the UMG, so I made this event bind function:
which works, it seems… so all good for now.
But then I asked myself if I could decouple this function, in order to apply it to any other button I want without having to declare a variable and a bind function for each button-text.
Maybe I’m overthinking this, because my game actually needs about four buttons, so I don’t really need a system right now, but if I had many more buttons, what would be the right approach?
I would do it by creating a custom widget with a button and a text. Add events on clicked and hovered. When these events fire set the color of the text to what ever you want. I suggest using color variables and setting them to public so you can modify later.
Your newly created widget will be available in the Palette of the UMG editor under User Created category.
You need to make sure the text is a variable. Then create a text or string variable and make it public.
On construct or Pre-construct set the text.
Also if you want to intercept the button presses you need to create event dispatchers.
Trying to figure out how to customize the text appearence I totally forgot that the button actually had to callback the click event to execute some code on click… the event dispatcher saved me, so thank you!