Hello,
I try to retrive controllers mouse position in widgets blueprint like so, but for some reason it returns false and null position. Any ideas why it doesnt work?
Try plugging a controller into the target node.
It’s not possible, Target node takes widget reference. I tried plugging self reference to it, as well as getting player controller from getplayercontroller with index 0. Nothing works.
The node on the GetMouse is kind of misleading, try it like this:
I actually found out that it works in event graph, but not in drag over function. It also stops updating position when I start drag operation. I have no idea why.
Ah, that explains it… somewhat. I have encountered many bugs related to the drag operation. I suggest you report it on answer hub.
Okay, so it turns out mouse movement is somehow not tracked during drag operation so I’ll have to figure out way to get correct coordinates from pointer event. Anyway, thanks for suggestions.
When the mouse button is in a clicked down state, mouse position is not tracked. This is seen more easily by creating a 3D widget with a slider and attempting to change the slider with the Widget Interaction Component set on mouse mode.
It is tracked but not by the controller. Drag movements take over and you should be able to get mouse position data from the pointer event.
While this allows you from the pointer event to get the screen space position and last screen space position and works perfectly fine in full screen it is horribly askew in windowed.
FVector2D UUtilityFunctionLibrary::GetMousePosition()
{
if (UWorld* World = GetGameWorld())
{
if (const APlayerController* PlayerController = UGameplayStatics::GetPlayerController(World, 0))
{
float X, Y;
// GetMousePosition does NOT work while Drag and Drop operations are active! Mouse is null during drag. Therefore we have a fallback option below.
if (PlayerController->GetMousePosition(X, Y))
{
const FVector2D PixelPosition = FVector2D(X, Y);
return PixelPosition;
}
}
const FVector2D MousePositionOnPlatform = UWidgetLayoutLibrary::GetMousePositionOnPlatform();
FVector2D PixelPosition;
FVector2D ViewportPosition;
USlateBlueprintLibrary::AbsoluteToViewport(World, MousePositionOnPlatform, PixelPosition, ViewportPosition);
return PixelPosition;
}
return FVector2D::ZeroVector;
}