Dear experts,
I am trying to make an inventory slot (UUserWidget) I can drag out of the inventory
and drop it to get rid of an inventory item.
This is my .cpp file:
//constructor
UInventorySlot::UInventorySlot(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
void UInventorySlot::NativeConstruct()
{
Super::NativeConstruct();
}
FReply UInventorySlot::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
const FEventReply reply = UWidgetBlueprintLibrary::DetectDragIfPressed(InMouseEvent, this, EKeys::LeftMouseButton);
const FVector2D DragOffset = InGeometry.AbsoluteToLocal(InMouseEvent.GetScreenSpacePosition());
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, TEXT("Drag: On Mouse Button Down"));
return reply.NativeReply;
}
void UInventorySlot::NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent,
UDragDropOperation*& OutOperation)
{
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, TEXT("NativeOnDragDetected"));
const auto DragVisual = CreateWidget<UInventorySlot>(this, UInventorySlot::StaticClass());
DragDropOperation->DefaultDragVisual = DragVisual;
DragDropOperation->Payload = this;
DragDropOperation->Pivot = EDragPivot::MouseDown;
DragDropOperation->Offset = InGeometry.AbsoluteToLocal(InMouseEvent.GetScreenSpacePosition());
if(DragVisual)
{
DragVisual->AddToViewport();
}
OutOperation = DragDropOperation;
}
I can see my inventory slots (I have Blueprints also) but if I click on one I can’t drag it. Also the ScreenDebugMessages of methods
FReply UInventorySlot::NativeOnMouseButtonDown
void UInventorySlot::NativeOnDragDetected
are not shown on the screen.
Please help, what am I doing wrong?
Best regards, Peter