Search Unity

Supporting N touches

Discussion in 'Input System' started by LaneFox, Feb 26, 2020.

  1. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    It's unclear how to approach Touch support. Is it directly in the Touchscreen class or should we be setting up individual touch actions?

    I'm really just looking for a way to track all of the touches on a device, in the event that we have 2, 6, or 12 touches at any given time and whether or not they're pinch.

    Additionally, Unity Remote doesn't seem to work with New Input System, so this makes it a real pain to test anything. Is there any workaround?
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    Some feedback would be much appreciated
     
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    For that, I'd recommend polling via the EnhancedTouch API.

    Code (CSharp):
    1. // Somewhere in init code:
    2. EnhancedTouchSupport.Enable();
    3.  
    4. // In touch processing code:
    5. var activeTouches = Touch.activeTouches;
    6. for (var i = 0; i < activeTouches.Count; ++i)
    7.     /* ... */;
    8.  
    9. // Or alternatively use the Finger API.
    This is pretty much akin to what you'd do with the UnityEngine.Touch API.

    Mapping touches via actions I'd only recommend for setups where you want to route touch input into the same input processing paths as other forms of input. Where that isn't useful, throwing actions into the mix will only complicate things.

    We're pushing on the Unity Remote front. Hopefully there's some news somewhat soonish.

    As for workarounds, one thing you can do is enable touch simulation in the editor (in the input debugger's "Options" dropdown). Admittedly, that's pretty limited as it can't simulate multi-touch.
     
    LaneFox likes this.
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    Thanks so much for the feedback, @Rene-Damm

    I threw some code together to experiment with and attempt tracking pinches (is there any built-in way to do that?), will let you know how it goes when I get some hands on the target hardware to test with next week.

    Is there any preview docs for this API or do we need to just poke it and see what happens for now?
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Not yet. Gesture support is on the high-priority list for after 1.0.

    There's some API docs but it's not that great ATM. In terms of examples, we only have the tests ATM. Definitely a situation that needs improvement.