I have a subclass of UUserWidget which I want to make a floating widget. I.e. if the user clicks on the widget and drags the mouse, the widget should follow the mouse.
I keep track of the user pressing the mouse button when over the widget, but I can’t get the widget to move.
FReply USRSFloatingWidget::NativeOnMouseMove(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
if (bIsMouseButtonDown)
{
FVector2D delta = InMouseEvent.GetCursorDelta();
GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, delta.ToString());
this->SetPositionInViewport(InGeometry.GetAbsolutePosition() + delta);
}
return FReply::Handled();
}
The Debug message tells me that delta
is not 0, but SetPositionInViewport
does not do anything and I couldn’t find a different method for setting the position.