Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question One finger touch but got fingerId 1

Discussion in 'Scripting' started by Dr_don, May 9, 2024.

  1. Dr_don

    Dr_don

    Joined:
    Dec 25, 2020
    Posts:
    2
    Hello, I am trying to output all Input.touches in each frame. In the case of a quick click with only one finger, I obtained a touch with fingerId 1 and also a touch with fingerId 0, with a time difference of 1ms or even 0. Sometimes use two fingers can also result in some touches with fingerId greater than 1. I want to know if this is because some touch lifecycles have not yet fully ended, and if there is any solution. Thank you!
     
  2. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    231
    From the docs:
    "You cannot make any assumptions about fingerId and the number of fingers actually on screen"

    The id's are mainly there to keep track of where a finger moves from one frame to another because the fingerId is kept the same as long as that finger is on the screen
     
    Bunny83 and spiney199 like this.
  3. Dr_don

    Dr_don

    Joined:
    Dec 25, 2020
    Posts:
    2
    Got it, thanks!
     
    venediklee likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,015
    Yes, what @venediklee says exactly... think of it just as an identifier to let you reconnect the same touch regardless of where it appears in the array of touches.

    If you want to see a simple example of it in action, see my
    VAButton
    class here:

    https://github.com/kurtdekker/proxi...y_buttons/Assets/ProximityButtons/VAButton.cs

    Line 88
    int fingerId;
    tracks the finger involved in this VAButton

    NOTE: all my code goes through a wrapper class called
    MicroTouch
    so that I don't have to write separate code paths for mouse and touch.

    https://github.com/kurtdekker/proxi...buttons/Assets/ProximityButtons/MicroTouch.cs