# SetBorderImage binded function is reset in Press and Release function

**URL:** <https://forums.unrealengine.com/t/setborderimage-binded-function-is-reset-in-press-and-release-function/551763>\
**Category:** UI\
**Tags:** unreal-engine, Engine-Source-Code, UE5-0, slate, CPP, question\
**Created:** [May 8, 2022, 7:06am UTC](https://forums.unrealengine.com/t/setborderimage-binded-function-is-reset-in-press-and-release-function/551763 "2022-05-08T07:06:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![domzorg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domzorg/32/906605_2.png) [@domzorg](https://forums.unrealengine.com/u/domzorg)\
**Post date:** [May 8, 2022, 7:06am UTC](https://forums.unrealengine.com/t/setborderimage-binded-function-is-reset-in-press-and-release-function/551763/1 "2022-05-08T07:06:47Z")

</div>

I have a class deriving from SButton

In the Construct, I bind a function for the button’s border image.

> SButton::Construct(ButtonArgs);  
> SetBorderImage(TAttribute\<const FSlateBrush\*\>(this, &SKButton::GetButtonImage));

The problem resides in SButton::Press() and SButton::Release()  
Both functions resets the binding

> void SButton::Press()  
> {  
> if ( !bIsPressed )  
> {  
> bIsPressed = true;  
> PlayPressedSound();  
> OnPressed.ExecuteIfBound();  
> UpdatePressStateChanged();  
> }  
> }  
> void SButton::Release()  
> {  
> if ( bIsPressed )  
> {  
> bIsPressed = false;  
> OnReleased.ExecuteIfBound();  
> UpdatePressStateChanged();  
> }  
> }  
> void SButton::UpdatePressStateChanged()  
> {  
> UpdatePadding();  
> UpdateBorderImage();  
> UpdateForegroundColor();  
> }

The function UpdateBorderImage() resets the binding

> void SButton::UpdateBorderImage()  
> {  
> if (!GetShowDisabledEffect() && !IsInteractable())  
> {  
> SetBorderImage(&Style-\>Disabled);  
> }  
> else if (IsPressed())  
> {  
> SetBorderImage(&Style-\>Pressed);  
> }  
> else if (IsHovered())  
> {  
> SetBorderImage(&Style-\>Hovered);  
> }  
> else  
> {  
> SetBorderImage(&Style-\>Normal);  
> }  
> }

Therefore I have to set back the binding after Press() and Release()

> const FSlateBrush\* SKButton::GetButtonImage() const  
> {  
> if (IsSelected())  
> {  
> if (IsPressed())  
> {  
> return &SelectedStyle-\>Pressed;  
> }  
> else if (IsHovered())  
> {  
> return &SelectedStyle-\>Hovered;  
> }  
> else  
> {  
> return &SelectedStyle-\>Normal;  
> }  
> }  
> return SBorder::GetBorderImage();  
> }  
> void SKButton::Press()  
> {  
> SButton::Press();  
> // We have to set back the function for getting the button image  
> // since in UE5 after Press() the border attribute is set again  
> SetBorderImage(TAttribute\<const FSlateBrush\*\>(this, &SKButton::GetButtonImage));  
> }  
> void SKButton::Release()  
> {  
> SButton::Release();  
> // We have to set back the function for getting the button image  
> // since in UE5 after Press() the border attribute is set again  
> SetBorderImage(TAttribute\<const FSlateBrush\*\>(this, &SKButton::GetButtonImage));  
> }

To avoid this problem, the function SButton::UpdateBorderImage() should be in protected and overridable or should check if the border image in SBorder is binded to a function.

D.
