# UMG - get hovered button and assign to variable

**URL:** <https://forums.unrealengine.com/t/umg-get-hovered-button-and-assign-to-variable/481682>\
**Category:** UI\
**Tags:** buttons, Navigation, unreal-engine, slate, UI, question, UMG\
**Created:** [April 9, 2021, 9:34pm UTC](https://forums.unrealengine.com/t/umg-get-hovered-button-and-assign-to-variable/481682 "2021-04-09T21:34:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicobu7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nicobu7](https://forums.unrealengine.com/u/nicobu7)\
**Post date:** [April 9, 2021, 9:34pm UTC](https://forums.unrealengine.com/t/umg-get-hovered-button-and-assign-to-variable/481682/1 "2021-04-09T21:34:34Z")

</div>

Hi, simple thing:

I have a custom widget that tracks the current button for gamepad navigation in a CurrentButton variable. Gamepad navigation works.  
However, when a button is hovered with the mouse, I want to do assign that hovered button to the CurrentButton variable so that the next time I switch to my gamepad, navigation starts from there and not from the previously selected button.

No Tick stuff and no custom button wanted. I want to do everything in the widget (specifically it is not a widget but a custom navigation class).

I couldn’t get OnHovered delegates to take the hovered button as a parameter. Might just be too dumb.

That description is a simplification. My navigation system is much more complex and revolves around tracking that CurrentButton variable and I am very proud to not having to use Tick events to track focused state or sth.

Thanks!  
Nico

---

<div class="post-metadata">

**Author:** ![nicobu7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nicobu7](https://forums.unrealengine.com/u/nicobu7)\
**Post date:** [April 10, 2021, 9:21pm UTC](https://forums.unrealengine.com/t/umg-get-hovered-button-and-assign-to-variable/481682/2 "2021-04-10T21:21:21Z")

</div>

Resolved. However, I hat to create my own Button class:

```
// ***UMGNavButton.h***************************************************
// #includes
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCustomHoverDelegate, UUMGNavButton*, Button);
 
UCLASS()
class UMGNAV_API UUMGNavButton : public UButton {
  GENERATED_BODY()
 
public: // variables
  UUMGNavButton();
 
  UPROPERTY()
    FCustomHoverDelegate CustomHover;
 
public: // functions
  UFUNCTION()
    void OnHover();
};

// ***UMGNavButton.cpp***************************************************
// #includes
UUMGNavButton::UUMGNavButton() {
  OnHovered.AddDynamic(this, &UUMGNavButton::OnHover);
}

void UUMGNavButton::OnHover() {
  CustomHover.Broadcast(this);
}

// ***UUMGNavExplicitButtonNavigator.h*********************************************
// #includes
UCLASS(BlueprintType)
class UMGNAV_API UUMGNavExplicitButtonNavigator : public UUMGNavNavigator {
  GENERATED_BODY()
  
public: // variables
  UPROPERTY(BlueprintReadOnly, Category = "UMGNav")
    UUMGNavButton* CurrentButton;

public: // functions
  UFUNCTION(BlueprintCallable)
    void AddNavButton(UUMGNavButton* _Button);  

  UFUNCTION(BlueprintCallable)
    void HoverButtonEvent(UUMGNavButton* _Button);   
}

// ***UUMGNavExplicitButtonNavigator.cpp*****************************************
// #includes
void UUMGNavExplicitButtonNavigator::AddNavButton(UUMGNavButton* _Button) {
  if(!Button->CustomHover.IsBound()) {
    Button->CustomHover.AddDynamic(this, &UUMGNavExplicitButtonNavigator::HoverButtonEvent);
  }
}

void UUMGNavExplicitButtonNavigator::HoverButtonEvent(UUMGNavButton* _Button) {
	CurrentButton = _Button;
}
```
