In my project I use “Get Mouse Position on Viewport” to place items in my level.
How can I manage in android that a mouse pointer is always displayed (without which a mouse is connected), with show maus curser it does not work.
I want to move the curser like anydek, for example.
Hi,I have encountered this problem too, have you made any new progress? I am running on the UE’s emulator ES3.1 and everything is normal, and I can get the screen coordinates, but in the physical machine, the obtained coordinates are always (0,0)
Reviving this because I found a solution:
Get Mouse Position on Viewport try to get Cursor position, which is not where touch is on Android:
UE::Slate::FDeprecateVector2DResult FSlateUser::GetCursorPosition() const
{
return GetPointerPosition(FSlateApplication::CursorPointerIndex);
}
To get the correct touch position, you need to use FSlateUser::GetPointerPosition instead and pass the correct TouchIndex as parameter. So I made a similar function to GetMousePositionOnViewport like this, for Mobile (for most cases, the TouchIndex will be 0, unless you want something multi-touches):
FVector2D UWidgetLayoutLibrary::GetTouchPositionOnViewport(UObject* WorldContextObject, int32 TouchIndex)
{
if (FSlateApplication::IsInitialized())
{
FVector2D MousePosition = FSlateApplication::Get().GetCursorUser()->GetPointerPosition(TouchIndex);
FGeometry ViewportGeometry = GetViewportWidgetGeometry(WorldContextObject);
return ViewportGeometry.AbsoluteToLocal(MousePosition);
}
return FVector2D(0, 0);
}