Getting world space location from DragDrop UMG event.

I am trying to get the location of my mouse in 3D space using
PlayerController()->DeprojectMousePositionToWorld
but it always fails. I assume it’s because the dragged UMG widget has set the controller to UI focus instead of Game focus?

EDIT: I can get the mouse pos on-screen while dragging UMG’s, through the UMG itself, but not through the OwningPlayerController, it is also a valid controller.

EDIT2: Trying to get the mouse pos scaled with DPI works for one tick. I assume it’s the tick that is before the focus switch. (UI to Game)

How do I get around this?

The controller does not know what’s happening to the mouse during drag and drop. The drag operation does have all the data. So you can project into the world from that:

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/110205-getting-mouse-position-during-drag-and-drop-umg?p=1513750#post1513750

FVector mouseToWrldLoc;
FVector mouseToWrldDir;
FVector2D ScreenPosition;

float dpis = UWidgetLayoutLibrary::GetViewportScale(GetOwningPlayer());
FVector2D loc = UWidgetLayoutLibrary::GetMousePositionOnViewport(GetWorld()) * dpis;
UGameplayStatics::DeprojectScreenToWorld(GetOwningPlayer(), loc, mouseToWrldLoc, mouseToWrldDir);

FHitResult hit;

if (UKismetSystemLibrary::LineTraceSingle(GetWorld(), mouseToWrldLoc, mouseToWrldLoc + (mouseToWrldDir * 1000), ETraceTypeQuery::TraceTypeQuery1, true, ignoreLineTraces, EDrawDebugTrace::Type::None, hit, true))
{
	currentDraggedItemSpawnedActor->SetActorLocation(hit.Location);
}
else
{
	currentDraggedItemSpawnedActor->SetActorLocation(mouseToWrldLoc + (mouseToWrldDir * 1000));
}

I used this in a UUserWidget, it replicates the way UE4 drags and drops assets into a world.