# \[UserWidget\] Setting an Image on PostEditChangeProperty

**URL:** <https://forums.unrealengine.com/t/userwidget-setting-an-image-on-posteditchangeproperty/680078>\
**Category:** C++\
**Tags:** unreal-engine, Widget, CPP, question\
**Created:** [October 30, 2022, 7:27am UTC](https://forums.unrealengine.com/t/userwidget-setting-an-image-on-posteditchangeproperty/680078 "2022-10-30T07:27:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RedYggdrasil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/redyggdrasil/32/573746_2.png) [@RedYggdrasil](https://forums.unrealengine.com/u/RedYggdrasil)\
**Post date:** [October 30, 2022, 7:27am UTC](https://forums.unrealengine.com/t/userwidget-setting-an-image-on-posteditchangeproperty/680078/1 "2022-10-30T07:27:32Z")

</div>

Hello there!

I have a problem with a `UUserWidget` blueprint overridden from a C++ Class, I try to set a Uimage’s Brush with a new Texture2D\* in C++ at editor time, but the changes are reverted when I compile the child blueprint inheriting from my UuserWidget.

* * *

I have made a `UWHButton` c++ class with inherit `UuserWidget`.  
This UWHButton is then used as a base class for Blueprint Widget classes.  
And those Blueprint Widget Classes can then be used in other Blueprint Widgets, as custom buttons with my C++ logic packaged in them.

What failed is when I tried to provide a simple `Texture2D*` field (`Inner Icon Texture`) in the Details panel to permit designers to customize my button’s appearance from the root object in the blueprint and from any other widget blueprint using the button as well.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/c/0dccf11d51d201f36da605b92c5b1fb2d012d940.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/c/29c8f7cfe8d39ffff7abc3e7c45152d6bf08fe0c.png)  
When the user change the `Texture2D*` field `_innerIconTexture` of my custom class in the details panel, I change the `Uimage` `_innerIconImage`’s `FSlateBrush` with the new `Texture2D*` in a `PostEditChangeProperty`.

> #if WITH\_EDITOR  
> void UWHButton::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)  
> {  
> FProperty\* innerIconProperty = FindFProperty(this-\>GetClass(), “\_innerIconTexture”);  
> if (innerIconProperty && (PropertyChangedEvent.Property == innerIconProperty))  
> {  
> FStructProperty\* uIBrushPropStruct = FindFProperty(\_innerIconImage-\>GetClass(), “Brush”);  
> if (uIBrushPropStruct)  
> {  
> \_innerIconImage-\>PreEditChange(uIBrushPropStruct);  
> FPropertyChangedEvent changedEvent = FPropertyChangedEvent(uIBrushPropStruct, EPropertyChangeType::ValueSet);
> 
> ```
> _innerIconImage->SetBrushFromTexture(_innerIconTexture);
> 
> _innerIconImage->MarkPackageDirty();
> _innerIconImage->PostEditChangeProperty(changedEvent);
> }
> 
> ```
> 
> }  
> Super::PostEditChangeProperty(PropertyChangedEvent);  
> }  
> #endif  
> (Image version of code as indentation is broken)
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/3/b63075a81493ba45ef288e8d9e3a5f2d0c3b1619.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/e/3de9232fb15ae16cac08b8abd7ce7a3ec79f7d8f.png)

* * *

However, as soon as I try to compile the changes to the blueprint, the changes on the `UImage` `_innerIconImage` have reverted to their previous state :

* * *

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/9/909edadd126c64ef94ffc6706db1d81d3a078162.png)

* * *

This is quite a problem as I wanted my `UWHButton` to be usable in other UserWidget blueprints, and so only the root parameters are accessible there, not the child components. So I cannot modify the child component UImage in editor directly, only the custom field.

I search the internet but found little than would help me understand the issue.

I came across this thread : [C++ property modifications (PostEditChange) are not saved](https://forums.unrealengine.com/t/c-property-modifications-posteditchange-are-not-saved/603526)

And so tried to set the value in a `PreSave` function but the `UImage` pointer is null at PreSave time, so I can’t set it there.

I also tried multiple things with `NativeConstruct` but with little success there as well.

If anyone has either a solution, an explanation or a workaround I would be grateful, because making a custom button doesn’t seem at all a complicated endeavor, I don’t get what is it I do so terribly wrong.

Thanks for reading me !

RedYggdrasil,  
Wannabe developer.

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [November 5, 2022, 10:12pm UTC](https://forums.unrealengine.com/t/userwidget-setting-an-image-on-posteditchangeproperty/680078/2 "2022-11-05T22:12:26Z")

</div>

The common way to set up widgets is through the OnInitialized / PreConstruct / Construct methods. OnInitialized conditionally only runs once when the game starts. Preconstruct runs at least once in both the editor and in-game. Construct runs at least once in-game. You should read the Texture2D property during PreConstruct in c++ and set the appearance from there.

---

<div class="post-metadata">

**Author:** ![RedYggdrasil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/redyggdrasil/32/573746_2.png) [@RedYggdrasil](https://forums.unrealengine.com/u/RedYggdrasil)\
**Post date:** [November 5, 2022, 11:23pm UTC](https://forums.unrealengine.com/t/userwidget-setting-an-image-on-posteditchangeproperty/680078/3 "2022-11-05T23:23:20Z")

</div>

> [@Roy\_Wierer.Seda145](#):
>
> Preconstruct runs at least once in both the editor and in-game. Construct runs at least once in-game.

Yep !  
Was using NativeConstruct, changing it to NativePreConstruct did the trick.  
Thanks a lot ! I spent so much time on so stupid a mistake, I’ll definitively remember this one 😅

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/c/0ec79fc7f51d6cca59c8bb60abc3f02943170eb8.png)

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/1/9f1a2bc67dcce28c7724033e4f5d603b8ec6ea8e.png)
