Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feedback Add API to allow reading Input System current time in double-precision (currently internal)

Discussion in 'Input System' started by Neonlyte, Jul 6, 2020.

  1. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    I am reworking a rhythm game project. Previously I poll Input.touches in MonoBehavior.Update and dispatch my own touch events based on the touch information. I since noticed that there may be chances that touch event updates may not align with the MonoBehavior update, and that few milliseconds difference between updates is actually important for accurate timings. Even though this has not been an issue among my players whatsoever, I want to try to eliminate this by using Touch.time provided in the new Input System.

    While the doc states the timeline is essentially Time.realtimeSinceStartup, that particular property is single-precision, and will lose precision by millisecond after several hours of play. I could ask player to restart the game after a few hours but that sounds like a terrible UX. Because of this, I am looking for ways to get time on that timeline with matching precision of input system timestamps

    I did notice that there were lower level APIs to query the "currentTime" of the system until they all went internal at some point. I wonder what were the decisions of closing accesses and whether there could be any public APIs added to read double-precision time
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    The current time (in double-precision) on the input event timeline can be queried via

    Code (CSharp):
    1. InputState.currentTime
    Lacks documentation and this particular property should probably be available directly from the InputSystem class rather than being hidden in the lower-level InputState.
     
  3. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    Thank you so much! And yes, I agree that this property should be more prominent in the documentation.
     
    GilbertoBitt likes this.
  4. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    @Rene-Damm I took a look at that API. I noticed that the returned value does not line up with the timestamp of the touch. Like, if I start the play mode in editor and observe "Touch.time", I found that the touch time would always start from zero, but InputState.currentTime would have some head-start time and it does not reset when I exit and reenter play mode. I can also observe this issue in iOS runtime. Is this expected? I thought InputState.currentTime should also reset?

    upload_2020-7-12_12-2-50.png
     
    Last edited: Jul 12, 2020
  5. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    ………………I fixed the issue by flipping the plus sign to minus in InputState.cs:
    @Rene-Damm Do I need to file bug report to get it fixed, or can I make a pull request on GitHub?

    Update: It seems that this was corrected 4 days ago in this commit. When can I expect this fix to be available to 2019.4?

    Code (CSharp):
    1. // Before:
    2. public static double currentTime => InputRuntime.s_Instance.currentTime + InputRuntime.s_CurrentTimeOffsetToRealtimeSinceStartup;
    3.  
    4. // After:
    5. public static double currentTime => InputRuntime.s_Instance.currentTime - InputRuntime.s_CurrentTimeOffsetToRealtimeSinceStartup;
    upload_2020-7-12_12-4-23.png
     
    Last edited: Jul 12, 2020
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Sorry about the slow response. Yeah, there was an embarrassing mistake in that API which has since been fixed, as you have discovered.

    1.1-preview is expected to be out within a week or two.