How I can do drag and drop in C ++?

I need to drag and drop in C ++ as I show in the image. I do not know how to do it.

Code:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"
#include "Runtime/UMG/Public/Blueprint/DragDropOperation.h"
			

#include "Blueprint/UserWidget.h"
#include "BatallaUserWidget.generated.h"

/**
 * 
 */
UCLASS()
class BATALLA_API UBatallaUserWidget : public UUserWidget
{
	GENERATED_BODY()

public:
		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu")
		FString MyNewWidgetName;

		/** Handle the block being clicked */
		UFUNCTION()
		void BlockDragEnter();

//		virtual FReply OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent);

// HERE ERROR!!!!!!!!
		void OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent,UDragDropOperation*& Operation) override;


		UButton* exitButton;
		bool presionado;

		
	void init();

	bool isClicked;

//	virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent&InMouseEvent) override;

//	virtual void NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent,UDragDropOperation*& InOperation) override;

//	virtual bool NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent, UDragDropOperation* InOperation) override;


	UFUNCTION(BlueprintCallable, Category = "SunShine")
	void ActivateSunShine();
	
};

What error do you get?

UFUNCTION(BlueprintNativeEvent, BlueprintCosmetic, Category = “Drag and Drop”)
void OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent, UDragDropOperation*& Operation);

error: In BatallaUserWidget: OnDragDetected: An override of a function cannot have a UFUNCTION() declaration above it; it will use the same parameters as the original base declaration.

How I can perform a drag and drop? I do not understand how to detect the beginning or end (OnDrop) operation.

Not if you can tell which object is the one doing the operation.

Will you have any examples of how to do?

I need take a Button and do the drag and drop operation into a AActor. I only need to know:

1 - What button you pressed.

2 - While on the drag, where the cursor is located.(To display the icon)

3 - Where and when has become drop operation (OnDrop)

4 - Add the actor on the scene (I use LineTraceSingle, and then add to the escene). This is already done.

I do not speak good English, you speak Spanish?

I can show you by teamviewer the proyect, will you please? please please please…

Can anyone help me ?

did you tried removeing UFUNCTION() as error message glide you?

BatallaUserWidget.h

class BATALLA_API UBatallaUserWidget : public UUserWidget { GENERATED_BODY()

public:
// UFUNCTION(BlueprintNativeEvent, BlueprintCosmetic, Category = “Drag and Drop”)
void OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent, UDragDropOperation*& Operation);

BatallaUserWidget.cpp

void UBatallaUserWidget::OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent, UDragDropOperation*& Operation){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT(" inicia drag"));

}

COMPILE OK!!! , but nothing happens.You never gets the message.

Declere it this way

 void OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent, UDragDropOperation*& Operation) override;

Ok. This is the error message:

error C3668: ‘UBatallaUserWidget::OnDragDetected’ : method with override specifier ‘override’ did not override any base class methods

Solved: Im working now in HUD with boxhits.

Thank you! Best regards.

How did you solve it? I’m getting the exact same mistake :stuck_out_tongue:

NativeOnDragDetected