Hello,
I was trying to set up a button to start a Drag and Drop operation, instead of the classic MouseButtonDown.
This is the idea that I was trying to replicate.
At the moment, my slot has a MenuAnchor to display those buttons.
And when I click on the slot, the menu will open. After that, when I click on the Move button, it will “say to the slot” that it must start a DragDrop Operation, and the menu will be closed.
My problem here is to start the DragDrop Operation. I already tried different approaches without luck. I think that maybe I’m creating a new operation, but it’s not being returned to nowhere, something that happens on “NativeOnDragDetected”.
NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent,
UDragDropOperation*& OutOperation)
Below, there is my latest attempt:
I inherit my class from UUserWidget
and TSharedFromThis<SObjectWidget>
.
After the click on the button, it will say to the slot to run this function:
.cpp
void USlotLayout::BeginDragDrop(ULocalPlayer* LocalPlayer, UDragDropOperation* Operation, int32 PointerIndex) {
if (LocalPlayer /* && Operation*/ )
{
TSharedPtr<const FSlateUser> SlateUser = LocalPlayer->GetSlateUser();
FVector2D ScreenCursorPos = SlateUser->GetCursorPosition();
FVector2D ScreenDraggedPosition = SlateUser->GetCursorPosition();
const float DPIScale = UWidgetLayoutLibrary::GetViewportScale(LocalPlayer);
TSharedRef<FUMGDragDropOp> DragDropOp =
FUMGDragDropOp::New(Operation, PointerIndex, ScreenCursorPos, ScreenDraggedPosition, DPIScale, SharedThis(this));
LocalPlayer->GetSlateOperations().BeginDragDrop(DragDropOp);
}
}
And getting an error on ShareThis(this)
If you have any idea about what’s going on, or if you have another way to do it, I appreciate your help. I’m not sure if I gave enough information, but if you need something more to help me to fix this, just say it.
Thanks!