# How to set an image for UMG button in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501>\
**Category:** UI\
**Tags:** button, image, unreal-engine, question, CPP, UMG\
**Created:** [May 5, 2015, 11:39am UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501 "2015-05-05T11:39:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elringus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/elringus/32/1017568_2.png) [@Elringus](https://forums.unrealengine.com/u/Elringus)\
**Post date:** [May 5, 2015, 11:39am UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/1 "2015-05-05T11:39:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Azarus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Azarus](https://forums.unrealengine.com/u/Azarus)\
**Post date:** [May 5, 2015, 11:46am UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/2 "2015-05-05T11:46:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Elringus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/elringus/32/1017568_2.png) [@Elringus](https://forums.unrealengine.com/u/Elringus)\
**Post date:** [May 5, 2015, 11:53am UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/3 "2015-05-05T11:53:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d92ae5bd1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d92ae5bd1](https://forums.unrealengine.com/u/anonymous_user_d92ae5bd1)\
**Post date:** [May 20, 2015, 8:32am UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/4 "2015-05-20T08:32:30Z")

</div>

you can use this

UButton\* button = (UButton\*) yourUMG-\>GetWidgetFromName(TEXT(“ButtonName”));

if (button)  
{

```
button->WidgetStyle.Normal.SetResourceObject(yourTexture);
button->WidgetStyle.Normal.ImageSize = FVector2D(TexureSize);

```

}

---

<div class="post-metadata">

**Author:** ![Elringus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/elringus/32/1017568_2.png) [@Elringus](https://forums.unrealengine.com/u/Elringus)\
**Post date:** [May 20, 2015, 5:28pm UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/5 "2015-05-20T17:28:03Z")

</div>

Oh, thank you very much, it worked!

---

<div class="post-metadata">

**Author:** ![LuisAlaguna](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luisalaguna/32/570408_2.png) [@LuisAlaguna](https://forums.unrealengine.com/u/LuisAlaguna)\
**Post date:** [May 29, 2019, 2:14pm UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/6 "2019-05-29T14:14:40Z")

</div>

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 *"`.

---

<div class="post-metadata">

**Author:** ![Lui.YK](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lui.YK](https://forums.unrealengine.com/u/Lui.YK)\
**Post date:** [June 8, 2025, 2:28pm UTC](https://forums.unrealengine.com/t/how-to-set-an-image-for-umg-button-in-c/317501/7 "2025-06-08T14:28:37Z")

</div>

In case someone still finding the answer,  
You can,  
in .h:  
UTexture2D _buttonTexture; // maybe set it somewhere in your UWG editor..  
…  
in .cpp  
UButton_ button = (UButton \*) yourUMG-\>GetWidgetFromName(TEXT(“ButtonName”));  
if (button)  
{  
FSlateBrush slatebrush;  
slatebrush.SetResourceObject(buttonTexture);  
FButtonStyle bnStyle = button-\>WidgetStyle;  
bnStyle.SetNormal(slatebrush);  
button-\>SetStyle(bnStyle);  
}
