UMG Simulate Button States and Click

It seems strange that you can’t simulate states on the UMG widgets since it’s needed to navigate menus and buttons with a gamepad.

The functions are in the Slate class, to set mouse enter and mouse leave. I thought that I could call those to set the hovered state. I can’t just set the background color because it’s an image for hovered, not just a color change. The functions require a FGeometry as input though, and there’s no reference to it.

Does anyone know of how to get a button’s geometry so can call functions on it that require it as arguments, such as OnMouseEnter()?

Turned out, it wasn’t needed. Who should believe function parameters. They weren’t needed. I passed in null.

I’ll leave this here, sure someone else wants to set and unset hovered state.

void USimButton::SimulationHover(bool newHover)
{
FPointerEvent ptrEvent;

if (newHover)
{
	MyButton->OnMouseEnter(NullGeometry, ptrEvent);
}
else
{
	MyButton->OnMouseLeave(ptrEvent);
}

}

1 Like

As of Unreal 5.1 implemented with a UUserWidget containing a UButton*…

void UCustomButton::SetSelected()
{
	//references from UCustomButton.h (UCustomButton::UUserWidget)
	//UButton* Button;
	Button->GetCachedWidget()->OnMouseEnter(FGeometry(), FPointerEvent());
	//Button->GetCachedWidget()->OnMouseLeave(FPointerEvent());
}