In the new inputs system, correct way to get the touch position when a touch down event occurs?

tl;dr
I need to be able to get the current touch position when a touch down occurs and not just the fact the screen was touched.

Context
Version: Unity 2020.2.7f1
Game: I am building a drawing game that will run on mobile and desktop.
Gameplay: Whenever the player presses the left mouse button and moves the mouse on desktop, or touches down and drags on mobile a line should be drawn.

In the Input Actions I have defined (see screenshot)

  • PointerMove (works the same for mouse and touch)
  • LeftMouseButton
  • TouchDown

The problem is that on desktop if a left click happens then OnTouchDown and OnLeftMouseButton both get called.

I need to separate the handlers because it seems the only way I’ve found to get the touch position when a touch down occurs is to do this:

    public void OnTouchDown(InputValue value)
    {
        Vector2 pointerPosition = Touchscreen.current.position.ReadValue();
        pointerInside = ConvertToLocalPoint(pointerPosition, out Vector2 localPoint);
        pointerDown = value.Get<float>() == 1.0f;
        OnPointerDownChange();
    }

The issue is with this approach is that if hitting the left moues button causes it to be called as well, the touchscreen position seems to be Vector3.zero which causes the pointerInside to be incorrectly calculated.

It is important to know where the touch occurs because there is a limited area to draw that is the canvas on screen.

Thanks in advance to anyone who has any tips or links!

6925184--812645--Screen Shot 2021-03-11 at 5.55.20 PM.png

Forgot to note that I have tried the different values of “Pointer Behavior”

6925193--812648--Screen Shot 2021-03-11 at 6.05.15 PM.png

Also weird is that the reverse is not true. If I build a webgl target and run on safari mobile I only see OnTouchDown get called.

I also confirmed I do not have the touch simulation script enabled.

bump

bump