I need to set/change UButton images from C++ at runtime. I know how do it with a regular UImage (SetBrushFromTexture), but for UButton I just can’t find anything similar. Is that possible at all?
Yes its possible. Have a look at the FButtonStyle struct and the UButtonWidgetStyle class.
The UButton object has a WidgetStyle parameter. This is what you have to update.
I hope it helps.
Thank you for the answer!
I’ve seen the WidgetStyle parameter, but still coulnd’t find any way to set the image. Could you please specify what method should be used?
you can use this
UButton* button = (UButton*) yourUMG->GetWidgetFromName(TEXT(“ButtonName”));
button->WidgetStyle.Normal.SetResourceObject(yourTexture); button->WidgetStyle.Normal.ImageSize = FVector2D(TexureSize);
Oh, thank you very much, it worked!
What’s about if i’m getting my texture as a “UTexture2D”? How must i to load it?
I’m getting this problem:
"UTexture2D *" is incompatible with parameter of type "UObject *".