Current mouse cursor during drag operation

Hi,

I’ve implemented Drag & Drop for one widget blueprint using a DragDropOperation object. This is working nice but the player controller always uses the default mouse cursor during the dragging. Even when it’s not the default cursor specified in the player controller.

Does anyone have an idea how to change this? I’ve tried setting the current mouse cursor in the OnDragDetected event but this doesn’t work.

I have the same problem. I have found this:

FCursorReply FDragDropOperation::OnCursorQuery()
{
if ( MouseCursorOverride.IsSet() )
{
return FCursorReply::Cursor( MouseCursorOverride.GetValue() );
}

	if ( MouseCursor.IsSet() )
	{
		return FCursorReply::Cursor(MouseCursor.GetValue());
	}

	return FCursorReply::Unhandled();
}

FCursorReply FUMGDragDropOp::OnCursorQuery()
{
	FCursorReply CursorReply = FGameDragDropOperation::OnCursorQuery();

	if ( !CursorReply.IsEventHandled() )
	{
		CursorReply = CursorReply.Cursor(EMouseCursor::Default);
	}

Problem is that the Blueprint DragAndDropOperation is a UDragAndDropOperation and not a FDragAndDropOperation so we have no way to override the mouse cursor… Maybe it will help you.

I have the same problem, and I don’t think there is any workaround, so I fixed it by modifying the engine code.
Here is my pull request.
https://github.com/EpicGames/UnrealEngine/pull/11337/

In project settings there is an option for setting the cursor design using a widget. Making this empty also can ‘hide’ the cursor. (‘Empty’ being the created widgetbp)

image

and in the case of just using the standard cursor, when dragging a widget I would like it to change to the hand cursor and when releasing it to return to the default, I tried to do it here but when I try to drag it continues with the default cursor then after I release it it changes to the hand cursor

1 Like

Have you solved it?

I couldn’t find a solution. The only thing I did was do as my friend Macarmoni said, put a transparent cursor in place of the default in the game settings and when the game starts change the cursor to a secondary one so that it is not always transparent, only when dragging and dropping, it’s a gimmick unfortunately :confused:

the link is down, can you help us?

I found out ! You just have to “set hardware cursor” during your drag and it will change
2024-09-13_01h33_48

Follow this link to know more about hardware cursor.

It worked perfectly for me

Easier fix: in FUMGDragDropOp::OnCursorQuery() it uses SourceUserWidgetPtr’s overriden pointer if it exists (the object you’re starting the drag from). So enable the checkbox to override the cursor on that widget, then set the overriden cursor to whatever you want it to be at various stages. GrabHand when the mouse enters, Default when it leaves, GrabHandClosed when the drag is triggered, etc.

This is the function to use.

When using hardware cursors, make sure the cursor file is not an imported .uasset, you need the files in the correct directory, but not actually imported to the engine.

Go to Project Settings → Engine - User Interface → Hardware Cursors and define a directory where your cursor images are stored. Use your game name (content root folder) for the relative path.

For example, you need cursor_hand.png not cursor_hand.uasset. The png file will not actually be visible in the content browser in engine, but can be read this way. No need to add the file extension for the function call either, just the name.

Finally, make sure to add your hardware cursor directory to be cooked when packaging your project.

Project Settings → Packaging → Additional Non-Asset Directories to Package

Packaging

From the cursor path tooltip, you can also just add a Slate directory for your cursor files since that will always be cooked.