Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is the touch screen working yet?

Discussion in 'Input System' started by 5argon, Aug 11, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I am new here, and this is what I did so far :

    Screenshot 2018-08-12 01.42.15.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Tester : MonoBehaviour {
    6.  
    7.     public AudioSource aSource;
    8.     public InputOfTheYear inp;
    9.  
    10.     public void Awake()
    11.     {
    12.         Debug.Log($"Registered!!");
    13.         inp.HelloActionMap._HelloTouchAction.performed += callbackContext =>
    14.         {
    15.             Debug.Log($"Touching the screen! {callbackContext.ReadValue<Vector2>()}");
    16.             aSource.Play();
    17.         };
    18.     }
    19.  
    20.     public void OnEnable()
    21.    {
    22.        Debug.Log($"Enabled!!");
    23.        inp.Enable();
    24.    }
    25. }
    Screenshot 2018-08-12 01.42.48.png

    Are these all there is to make it work as I am copying what demo project is doing. But still I can't get the log message to show up. (Tested on a real Android device)

    Also what is the difference between the one with `touch` and without? For example there are touch/delta , touch/position and also just delta and position.

    Screenshot 2018-08-12 01.44.23.png
     
    Last edited: Aug 11, 2018
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Touchscreen is expected to (mostly) work. We have some bugs and some TODOs associated with it but it should largely give consumable input at this point.

    However, using Touchscreen devices together with input actions is something we still need to put some work into. The reason is that unlike any other InputDevice, Touchscreen performs some trickery to manage its internal state. The key thing it does differently is that it dynamically decided where in its own state to put incoming touch state. This is to avoid having touches overwrite one another within frames.

    Unfortunately, for actions it means that with what's there ATM they can't really track touches. I mean, if all you care about is detecting *any* activity on the Touchscreen, you can just bind to the entire device but meaningfully binding to individual touches or parts (such as position) of them is something that won't work ATM.

    Touchscreen is based on Pointer which adds certain controls every pointer is expected to expose (position, delta, etc). These are the ones without "touch/". Unfortunately, the ones inherited from Pointer aren't implemented correctly ATM. Touchscreen went through a number of transformations that ATM have left it as a bit of a misfit among the various devices. There will be a pass to deal with the fallout from all the state handling magic Touchscreen has acquired.
     
    5argon likes this.
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Hello @Rene-Damm , thanks for the assist. Binding to the entire device works for detecting any events.

    I would like to ask a question about the callback. The touch system is frame rate independent, but when will the callback happen? Is it sequentially in a frame together in one go containing all previous data from their capture time or is it realtime and can be at any moment while inside the frame?

    Anyways I have tried logging the touch vs. old event system and noticed some problems. All time logged use the time at that line of the code (realTimeSinceStartup) except the new input system which I use the time contained in the callback.

    - It shows that in some frame we get 2 callbacks after Initialization and before Update. If these callback is the accumulation of touches which happen before this frame then the time in those callbacks should always be earlier than the real time since startup I logged at Initialization because the touch must happen before the frame to be able to get processed this frame. But the log says time from new input system that is always later than the time at Initialization. Why?

    - The new input system is always 1-2 frame late than the old event system! I logged normal event trigger on every touch down too and it is faster every time. Is it supposed to be like this (a trade off that has to be made for the new system, or a bug?) since other than frame rate independent true touch capture time I also would like the earliest frame as possible that the program can detect any touch.

    With this 2 point both accuracy wise (being able to get correct touch time even if the frame skips) and latency wise (being to response in the earliest frame as possible after the finger touch) there is no reason to use the new input system for me.

    Code (CSharp):
    1. --- BEGIN frame : 22.2851
    2. UPDATE : 22.28549
    3. --- END frame : 22.30138
    4. --- BEGIN frame : 22.302
    5. UPDATE : 22.30242
    6. --- END frame : 22.31835
    7. --- BEGIN frame : 22.31898
    8. Normal touch : In-frame input time 22.3196
    9. UPDATE : 22.31979
    10. --- END frame : 22.33387
    11. --- BEGIN frame : 22.33436
    12. NEW input system! : Input time 22.3347091674805 22.3347091674805 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    13. UPDATE : 22.33535
    14. --- END frame : 22.35048
    15. --- BEGIN frame : 22.35142
    16. NEW input system! : Input time 22.351863861084 22.351863861084 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    17. UPDATE : 22.3528
    18. --- END frame : 22.3666
    19. --- BEGIN frame : 22.36707
    20. NEW input system! : Input time 22.3672981262207 22.3672981262207 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    21. NEW input system! : Input time 22.367748260498 22.367748260498 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    22. UPDATE : 22.36809
    23. --- END frame : 22.38333
    24. --- BEGIN frame : 22.38388
    25. UPDATE : 22.3844
    26. --- END frame : 22.39929
    27. --- BEGIN frame : 22.39981
    28. UPDATE : 22.4004
    29. --- END frame : 22.41717
    30. --- BEGIN frame : 22.41765
    31. UPDATE : 22.41804
    32. --- END frame : 22.43374
    33. --- BEGIN frame : 22.43423
    34. UPDATE : 22.43462
    35. --- END frame : 22.44806
    36. --- BEGIN frame : 22.44844
    37. UPDATE : 22.44887
    38. --- END frame : 22.46675
    39. --- BEGIN frame : 22.46723
    40. UPDATE : 22.46775
    41. --- END frame : 22.48621
    42. --- BEGIN frame : 22.49277
    43. Normal touch : In-frame input time 22.49446
    44. UPDATE : 22.49644
    45. --- END frame : 22.49985
    46. --- BEGIN frame : 22.50031
    47. NEW input system! : Input time 22.5006542205811 22.5006542205811 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    48. UPDATE : 22.50148
    49. --- END frame : 22.51426
    50. --- BEGIN frame : 22.51473
    51. NEW input system! : Input time 22.515043258667 22.515043258667 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    52. UPDATE : 22.51592
    53. --- END frame : 22.53094
    54. --- BEGIN frame : 22.53167
    55. NEW input system! : Input time 22.5320129394531 22.5320129394531 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    56. NEW input system! : Input time 22.5325889587402 22.5325889587402 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    57. UPDATE : 22.53327
    58. --- END frame : 22.54678
    59. --- BEGIN frame : 22.54719
    60. UPDATE : 22.54756
    61. --- END frame : 22.56488
    62. --- BEGIN frame : 22.56535
    63. UPDATE : 22.56572
    64. --- END frame : 22.57972
    65. --- BEGIN frame : 22.58009
    66. UPDATE : 22.5805
    67. --- END frame : 22.59701
    68. --- BEGIN frame : 22.59753
    69. UPDATE : 22.59794
    70. --- END frame : 22.61543
    71. --- BEGIN frame : 22.61592
    72. UPDATE : 22.61639
    73. --- END frame : 22.63055
    74. --- BEGIN frame : 22.63113
    75. UPDATE : 22.63158
    76. --- END frame : 22.64644
    77. --- BEGIN frame : 22.64714
    78. Normal touch : In-frame input time 22.64779
    79. UPDATE : 22.64798
    80. --- END frame : 22.66261
    81. --- BEGIN frame : 22.66309
    82. NEW input system! : Input time 22.6633911132813 22.6633911132813 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    83. NEW input system! : Input time 22.6639175415039 22.6639175415039 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    84. UPDATE : 22.66447
    85. --- END frame : 22.68093
    86. --- BEGIN frame : 22.68168
    87. UPDATE : 22.68247
    88. --- END frame : 22.69587
    89. --- BEGIN frame : 22.69632
    90. NEW input system! : Input time 22.6966190338135 22.6966190338135 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    91. UPDATE : 22.69709
    92. --- END frame : 22.71209
    93. --- BEGIN frame : 22.71252
    94. NEW input system! : Input time 22.7128562927246 22.7128562927246 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    95. UPDATE : 22.71382
    96. --- END frame : 22.73007
    97. --- BEGIN frame : 22.73054
    98. UPDATE : 22.73099
    99. --- END frame : 22.74607
    100. --- BEGIN frame : 22.74654
    101. UPDATE : 22.74739
    102. --- END frame : 22.7629
    103. --- BEGIN frame : 22.76344
    104. UPDATE : 22.76403
    105. --- END frame : 22.77975
    106. --- BEGIN frame : 22.78051
    107. Normal touch : In-frame input time 22.78129
    108. UPDATE : 22.78152
    109. --- END frame : 22.79585
    110. --- BEGIN frame : 22.79667
    111. UPDATE : 22.79734
    112. --- END frame : 22.81284
    113. --- BEGIN frame : 22.81453
    114. NEW input system! : Input time 22.8148822784424 22.8148822784424 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    115. UPDATE : 22.81567
    116. --- END frame : 22.8279
    117. --- BEGIN frame : 22.82877
    118. NEW input system! : Input time 22.8291435241699 22.8291435241699 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    119. UPDATE : 22.83133
    120. --- END frame : 22.84402
    121. --- BEGIN frame : 22.84453
    122. NEW input system! : Input time 22.8449020385742 22.8449020385742 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    123. NEW input system! : Input time 22.8453845977783 22.8453845977783 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    124. UPDATE : 22.84572
    125. --- END frame : 22.86107
    126. --- BEGIN frame : 22.86152
    127. UPDATE : 22.86198
    128. --- END frame : 22.87739
    This is the test code. NormalTouch called from the old event system with Pointer Down and Drag event trigger.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Entities;
    5. using Unity.Mathematics;
    6. using Unity.Collections;
    7. using Unity.Jobs;
    8. using UnityEngine.Experimental.PlayerLoop;
    9.  
    10. [UpdateBefore(typeof(Initialization))]
    11. public class BeginFrameTrackingSystem : ComponentSystem
    12. {
    13.     protected override void OnUpdate()
    14.     {
    15.         Debug.LogWarning($"--- BEGIN frame : {Time.realtimeSinceStartup}");
    16.     }
    17. }
    18.  
    19. [UpdateAfter(typeof(PostLateUpdate))]
    20. public class EndFrameTrackingSystem : ComponentSystem
    21. {
    22.     protected override void OnUpdate()
    23.     {
    24.         Debug.LogWarning($"--- END frame : {Time.realtimeSinceStartup}");
    25.     }
    26. }
    27.  
    28. public class Tester : MonoBehaviour {
    29.  
    30.     public AudioSource aSource;
    31.     public InputOfTheYear inp;
    32.  
    33.     public void Awake()
    34.     {
    35.         Debug.Log($"Registered!!");
    36.         inp.HelloActionMap._HelloTouchAction.performed += callbackContext =>
    37.         {
    38.             Debug.Log($"NEW input system! : Input time {callbackContext.time} {callbackContext.startTime} {callbackContext.action.name} {callbackContext.interaction} {callbackContext.phase} {callbackContext.control.name} {callbackContext.control.path} {callbackContext.action.phase}");
    39.             aSource.Play();
    40.         };
    41.     }
    42.  
    43.     public void Update()
    44.     {
    45.         Debug.LogWarning($"UPDATE : {Time.realtimeSinceStartup}");
    46.     }
    47.  
    48.     public void OnEnable()
    49.     {
    50.         Debug.Log($"Enabled!!");
    51.         inp.Enable();
    52.     }
    53.  
    54.     public void NormalTouch()
    55.     {
    56.         Debug.Log($"Normal touch : In-frame input time {Time.realtimeSinceStartup}");
    57.     }
    58.  
    59. }
     
    Last edited: Aug 12, 2018
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    As part of input processing which happens right before MonoBehaviour.FixedUpdate and right before MonoBehaviour.Update.

    It's batched together. Events are queued and not processed right away.

    Yes, input updates in both fixed and dynamic updates. Not every frame has fixed updates. You can turn off input processing in fixed updates altogether

    Code (CSharp):
    1. InputSystem.updateMask &= ~InputUpdateType.Fixed;
    We're still in the process of figuring out how to best deal with fixed updates.

    This is expected. Input time is not directly related to Time.realtimeSinceStartup. There's a change in the pipe to add a conversion function.

    Input time progresses linearly from the time Unity starts up. Time.realtimeSinceStartup unfortunately gets reset at various points. In the editor, it happens every time you enter play mode. In the player, it happens once when the first scene is loaded. This means that at every reset, all input timestamps will now appear to be in the future.

    The upcoming change remembers the current offset between the two timelines and adds a function to apply it.

    Late with respect to timestamps or late as in "I touch the screen and the same touch appears first in UnityEngine.Input.touches and then 1-2 frames later in Touchscreen"? Also, which platform is this on?
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Thanks about explanation of the touch timestamp. I didn't know they are not related since it appears to be so close.

    Late as in "I touch the screen and the same touch appears first in UnityEngine.Input.touches and then 1-2 frames later in Touchscreen". The platform is Android.

    From the adb logcat log I posted you can see that the log message "Normal Touch" which is from a public function I connected to Event Trigger is always coming first, then the message at end frame + start frame, then finally 1-2 message from the new input system callback. That means at least 1 frame has passed and if I want to put a code to react to the touch input the old system would be faster to react. (For musical apps reacting fast and play feedback sound as fast as possible is more important than getting the real touch time unfortunately)
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Thanks for the details. We'll look into it. Definitely not expected. I've created a ticket here.
     
    MechEthan and 5argon like this.
  7. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Since you mentioned Android in the ticket I have tested in iOS too. On iOS sometimes the new system is on the same frame as old system but still there are some frame that the old system comes 1 frame sooner.

    And the project I used to test is now up here : https://github.com/5argon/NewInputLatencyTest

    For some reason the ECS system I used to print the frame log message is not running on my iPod Touch Gen 5 while printing on Editor and Android. Not sure why, but I have submit that separately as a bug.

    Code (CSharp):
    1. UPDATE : 262.0726
    2. UPDATE : 262.1064
    3. UPDATE : 262.1392
    4. UPDATE : 262.1728
    5. UPDATE : 262.2058
    6. NEW input system! : Input time 262.2392578125 262.2392578125 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    7. Normal touch : In-frame input time 262.3111
    8. UPDATE : 262.3189
    9. NEW input system! : Input time 262.326477050781 262.326477050781 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    10. UPDATE : 262.3303
    11. NEW input system! : Input time 262.357971191406 262.357971191406 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    12. UPDATE : 262.3635
    13. NEW input system! : Input time 262.389404296875 262.389404296875 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    14. UPDATE : 262.3937
    15. UPDATE : 262.4229
    16. UPDATE : 262.4558
    17. UPDATE : 262.489
    18. UPDATE : 262.5231
    19. UPDATE : 262.556
    20. UPDATE : 262.5891
    21. UPDATE : 262.6228
    22. UPDATE : 262.6557
    23. UPDATE : 262.6892
    24. UPDATE : 262.7223
    25. NEW input system! : Input time 262.755584716797 262.755584716797 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    26. Normal touch : In-frame input time 262.763
    27. UPDATE : 262.7668
    28. NEW input system! : Input time 262.788940429688 262.788940429688 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    29. UPDATE : 262.7943
    30. NEW input system! : Input time 262.822204589844 262.822204589844 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    31. UPDATE : 262.8265
    32. NEW input system! : Input time 262.856079101563 262.856079101563 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    33. UPDATE : 262.8607
    34. UPDATE : 262.8898
    35. UPDATE : 262.9223
    36. UPDATE : 262.9563
    37. UPDATE : 262.9897
    38. UPDATE : 263.0225
    39. UPDATE : 263.0562
    40. UPDATE : 263.0897
    41. UPDATE : 263.1224
    42. NEW input system! : Input time 263.157897949219 263.157897949219 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    43. Normal touch : In-frame input time 263.1674
    44. UPDATE : 263.1749
    45. NEW input system! : Input time 263.18896484375 263.18896484375 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    46. UPDATE : 263.2057
    47. NEW input system! : Input time 263.222259521484 263.222259521484 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    48. UPDATE : 263.2326
    49. NEW input system! : Input time 263.255584716797 263.255584716797 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    50. UPDATE : 263.259
    51. UPDATE : 263.2889
    52. UPDATE : 263.3224
    53. UPDATE : 263.3558
    54. UPDATE : 263.3891
    55. UPDATE : 263.4234
    56. UPDATE : 263.4558
    57. UPDATE : 263.4892
    58. NEW input system! : Input time 263.522491455078 263.522491455078 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    59. Normal touch : In-frame input time 263.5283
    60. UPDATE : 263.5352
    61. NEW input system! : Input time 263.557403564453 263.557403564453 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    62. UPDATE : 263.5636
    63. NEW input system! : Input time 263.589019775391 263.589019775391 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    64. UPDATE : 263.5943
    65. UPDATE : 263.6234
    66. UPDATE : 263.6557
    67. UPDATE : 263.6904
    68. UPDATE : 263.7225
    69. UPDATE : 263.7557
    70. UPDATE : 263.7892
    71. UPDATE : 263.8224
    72. UPDATE : 263.8559
    73. UPDATE : 263.8892
    74. UPDATE : 263.9227
    75. UPDATE : 263.9572
    76. Normal touch : In-frame input time 263.9917
    77. UPDATE : 263.9969
    78. NEW input system! : Input time 264.022216796875 264.022216796875 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    79. NEW input system! : Input time 264.027465820313 264.027465820313 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    80. UPDATE : 264.0387
    81. NEW input system! : Input time 264.055603027344 264.055603027344 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    82. UPDATE : 264.0643
    83. NEW input system! : Input time 264.089263916016 264.089263916016 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    84. UPDATE : 264.095
    85. UPDATE : 264.1223
    86. UPDATE : 264.1558
    87. UPDATE : 264.1892
    88. UPDATE : 264.2229
    89. UPDATE : 264.2557
    90. UPDATE : 264.2891
    91. UPDATE : 264.3226
    92. UPDATE : 264.3561
    93. UPDATE : 264.3891
    94. UPDATE : 264.4227
    95. NEW input system! : Input time 264.455596923828 264.455596923828 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    96. Normal touch : In-frame input time 264.4617
    97. UPDATE : 264.4683
    98. NEW input system! : Input time 264.489196777344 264.489196777344 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    99. UPDATE : 264.4974
    100. NEW input system! : Input time 264.522399902344 264.522399902344 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    101. UPDATE : 264.5288
    102. NEW input system! : Input time 264.555816650391 264.555816650391 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    103. UPDATE : 264.5599
    104. UPDATE : 264.5889
    105. UPDATE : 264.623
    106. UPDATE : 264.6567
    107. UPDATE : 264.6895
    108. UPDATE : 264.7227
    109. UPDATE : 264.7564
    110. UPDATE : 264.7895
    111. UPDATE : 264.8228
    112. UPDATE : 264.8574
    113. UPDATE : 264.8894
    114. NEW input system! : Input time 264.922668457031 264.922668457031 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    115. Normal touch : In-frame input time 264.9517
    116. UPDATE : 264.9564
    117. NEW input system! : Input time 264.965667724609 264.965667724609 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    118. UPDATE : 264.9713
    119. UPDATE : 264.9922
    120. NEW input system! : Input time 265.0234375 265.0234375 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    121. NEW input system! : Input time 265.028991699219 265.028991699219 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    122. UPDATE : 265.0346
    123. UPDATE : 265.0591
    124. UPDATE : 265.0889
    125. UPDATE : 265.1227
    126. UPDATE : 265.1557
    127. UPDATE : 265.1889
    128. UPDATE : 265.2223
    129. UPDATE : 265.2558
    130. UPDATE : 265.2894
    131. UPDATE : 265.3229
    132. UPDATE : 265.3563
    133. UPDATE : 265.3894
    134. NEW input system! : Input time 265.422485351563 265.422485351563 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    135. Normal touch : In-frame input time 265.43
    136. UPDATE : 265.4348
    137. NEW input system! : Input time 265.456268310547 265.456268310547 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    138. UPDATE : 265.4627
    139. UPDATE : 265.4896
    140. NEW input system! : Input time 265.522338867188 265.522338867188 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    141. NEW input system! : Input time 265.527862548828 265.527862548828 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    142. UPDATE : 265.5356
    143. UPDATE : 265.5567
    144. UPDATE : 265.5893
    145. UPDATE : 265.6237
    146. UPDATE : 265.6557
    147. UPDATE : 265.6895
    148. UPDATE : 265.7229
    149. UPDATE : 265.7559
    150. UPDATE : 265.789
    151. UPDATE : 265.8228
    152. UPDATE : 265.8571
    153. Normal touch : In-frame input time 265.8913
    154. UPDATE : 265.8944
    155. NEW input system! : Input time 265.922180175781 265.922180175781 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    156. NEW input system! : Input time 265.928253173828 265.928253173828 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    157. UPDATE : 265.9339
    158. NEW input system! : Input time 265.956329345703 265.956329345703 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    159. UPDATE : 265.9651
    160. NEW input system! : Input time 265.989013671875 265.989013671875 HelloTouchAction  Performed Touchscreen /Touchscreen Performed
    161. UPDATE : 265.9937
    162. UPDATE : 266.0227
    163. UPDATE : 266.0561
    164. UPDATE : 266.0899
    165. UPDATE : 266.123
    166. UPDATE : 266.1557
    167. UPDATE : 266.1889
    168. UPDATE : 266.2223
    169. UPDATE : 266.2556
    170. UPDATE : 266.289
    171. UPDATE : 266.3231
     
    Seb-1814 likes this.
  8. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    sorry to bother and intrude. What's the old input system you're using on iOS?
     
  9. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    The old input system is a combination of Canvas + Graphic Raycaster + a full screen Panel with an Event Trigger on it. (Pointer down and drag). Finally that call the public method.

    Screenshot 2018-08-15 12.08.26.png
     
  10. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Wow. That is convoluted.

    Thank you for the response.

    I'm using

    if ( Input.touchCount != 0 ) { // manually handling touches in here}


    And this is working, but is it the best/fastest/lightest other way to handle touches?

    Are there any deficiencies to my (very lazy) approach?

    I want the least latency possible.
     
  11. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Ok we are in the same boat. I don't know about executing order whether the check for `Input.__` or the event system callback can potentially be earlier, but I have done an experiment before that the two give roughly the same touch response time. Because regardless of which one can be earlier in a frame, both is in the same frame. If the response you are aiming for is playing audio, then frame is the most granular unit we can achieve. If you get it in the same frame then probably you can't make any difference for audio. But if you can get it a frame earlier the difference could be significant.

    I have put some effort to make the input coming as fast as possible so I get more frame earlier. On Android it was a failure and I could not make it faster, you can read more here https://github.com/5argon/UnityiOSNativeAudio#update-3112017--the-state-of-android .

    On iOS however I successfully getting the native side to call (static) method similar to the way of Event System. It is significantly faster however the touch data is not as sophisticated. The solution is already on Asset Store, you can click on my signature to go to that or you can see the approach I take on the second tab of its home page http://exceed7.com/ios-native-touch/

    I am planning to deprecate the plugin as soon as the new system can make the latency come equal or faster than this native hack so that's why I am investigating this right now. (plus potentially get the Android touch faster where I failed)

    Edit : @Deeeds I tried again on my new phone. On Android where I said I failed actually it is a little bit faster now? (about 1 frame faster for 60 FPS game) But for some games this is quite significant.

    For perspective this is about a half of perfect window for many music games, 33ms. On game like DDR the timing for Marvelous (highest) is just 16ms so if you use vanilla Unity input to make DDR the player would be randomly thrown into or out of Marvelous. Also my plugin can get the native timestamp (similar to this new input system) so the time does not get locked to the frame rate.

    The approach I did is to override dispatchTouchEvent on the activity and send touch to Unity via AndroidJavaProxy callback method. (then still call super.that so the normal Unity input pipeline still works) The touch time from Android is faster than EventTrigger according to this table. I am planning to add Android functionality to the plugin later even if it is only this faster but if you want to follow now you can try that way.

    Ps. And I have confirmed that all Event Triggers will come before all of your Update where you have any chance to check for Input.___ in the same frame. Not a big deal but good to know.

    Screenshot 2018-08-16 17.14.32.png
     
    Last edited: Aug 18, 2018
    MechEthan, Seb-1814 and Deeeds like this.