UI Toolkit runtime touch inputs are offset when screen ratio is different from reference ratio

Hello ! I am practicing UI Toolkit on mobile devices and encountered a strange bug when using a different device.

When a PanelSettings Scale Mode is set to something different from Constant Pixel Size, all touch inputs seem to be offset. The issue occurs on actual devices but can be reproduced in the Device Simulator.

Here is an example :


In this document, I registered each VisualElement to PointerDown and PointerUp events. The ScaleMode is set to Scale With Screen Size, Match Mode is set to Height.
In the console, I display the name of the element receiving event and the pointerType of the event.
The screenshot shows what happened after clicking inside the orange rectangle.
By the way, for each up or down event, there are :
- two mouse events and one touch event, in the Device Simulator.
- one mouse event and one touch event, on an actual device.
I am not sure if this is normal behaviour.

  • When ScaleMode is set to Scale With Screen Size, it seems that touch input are offset when the screen resolution is different from the reference resolution.
  • When ScaleMode is set to ConstantPhysicalSize, no touch input event is received.

I am not sure what is the correct way to register to input event on mobile with UI Toolkit, but it seems that something is going wrong with touch input. This issue also impacts other controls like buttons. I haven’t tried yet to debug what is going on inside the EventSystem :smile:

Hello,

Would you mind reporting this through Unity > Help > Report a bug ?
Thanks

1 Like

Hi ! I reported the bug (Case 1288368).

I may have found the problem in EventSystem.cs :hushed: :

The coordinates are flipped after evaluating the input panel position, I’m not sure if it’s normal.
This way, the position seems to be evaluated wrong (l. 258) : Screen.height is not depending from panel scale whereas touch.position is in panel space coordinates.

Since I put the Y coordinates flip just before SendPositionBasedEvent(), I don’t have touch input offset anymore :smile:

4 Likes

Any news about this problem?

Should make it in preview 15, according to this issue tracker

I suppose this is currently fixed in Unity 2021.2 but haven’t checked yet

We are still on a custom version of preview 14, with above fix implemented

1 Like

Thank you @Midiphony-panda :slight_smile:
(do you have any tip about setting up a custom version of a plugin? I guess you could copy the com.unity.ui@1.0.0-preview.14 folder in the Assets folder but I hope there’s a better way)

On our side, we put it in the Packages folder :slight_smile:

You might have an issue with the @ for a folder inside Packages, so maybe rename the folder by something like com.unity.ui--1.0.0-preview.14-customfix

1 Like