im using widget local coords as offset in viewport when im dragging widgets, but its not working by some reason.
// at widget
FReply UInventoryWidget::NativeOnMouseButtonDown(const FGeometry & InGeometry, const FPointerEvent & InMouseEvent)
{
controller->PanelDrag(this, this->GetCachedGeometry().AbsoluteToLocal(InMouseEvent.GetScreenSpacePosition()));
return FReply::Handled();
}
// controller vars
UUserWidget* DraggingPanel;
FVector2D DraggingPanelOffset;
void PanelDrag(UUserWidget* panel, FVector2D offset) { DraggingPanel = panel; DraggingPanelOffset = offset; }
// at controller frame tick
void AController::Tick(float DeltaTime)
{
if (DraggingPanel)
{
MoveDraggingPanel();
}
}
void AController::MoveDraggingPanel()
{
FVector2D mouseposition;
GetMousePosition(mouseposition.X, mouseposition.Y);
DraggingPanel->SetPositionInViewport(mouseposition - DraggingPanelOffset);
}