Search Unity

Can't get touch position (v1.0.0)

Discussion in 'Input System' started by mattpwibbu, Mar 22, 2020.

  1. mattpwibbu

    mattpwibbu

    Joined:
    Jan 16, 2019
    Posts:
    6
    I have a simple input requirement to read the mouse/touch position only on click/touch. I don't want a constant polling of the mouse/touch position.

    My actions are defined as shown below.

    upload_2020-3-22_7-45-29.png

    upload_2020-3-22_7-47-10.png

    upload_2020-3-22_7-46-3.png

    The code currently works fine for Standalone (mouse) by using
    Code (CSharp):
    1. Mouse.current.position.ReadValue()
    . However, all of the code I have tried for mobile (touch) has not worked and I always get (0,0) as the position. I have tried the following methods:

    Code (CSharp):
    1. Touchscreen.current.primaryTouch.position.ReadValue()
    Result: (0,0)

    Code (CSharp):
    1. Touchscreen.current.touches[0].position.ReadValue()
    Result: (0,0)

    Code (CSharp):
    1. Touch.activeTouches[0].screenPosition
    Result: The activeTouches array is empty. In this situation, I have used the EnhancedTouchSupport.Enable() method before checking the Touch API, as the documentation dictates.

    Code (CSharp):
    1. Touch.activeFingers[0].screenPosition
    Result: Same as above, array is empty.


    I've no idea what I'm doing wrong here (if anything?). Are the Touch and Touchscreen APIs buggy?

    Thanks
     
    deus0 and Spica24510 like this.
  2. mattpwibbu

    mattpwibbu

    Joined:
    Jan 16, 2019
    Posts:
    6
    Hello? Anyone? I guess I'll report a bug...?
     
    deus0 likes this.
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Sorry to leave you having.

    What's the platform?

    To make 100% sure we're on the same page, you mean that *while* a finger is down, you get a (0,0) position from Touchscreen.current.primaryTouch.position? If so, please file a bug report.
     
  4. mattpwibbu

    mattpwibbu

    Joined:
    Jan 16, 2019
    Posts:
    6
    Hi and thanks for your response.

    Apologies for not being specific. The current platform I'm working on is Android, but we will be focusing on iOS as well. Also, to clarify, I'm trying to get the position in the editor as well by using touch simulation as outlined here.

    I have two actions defined, one with a Tap interaction restriction and another with a double-tap one. So, if I understand your leading here correctly, when my code gets called the touch wouldn't actually be happening. Is that correct? If so, how am I meant to get the position where the tap happened?

    Thanks for your help.
     
  5. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    Any luck? :)