Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

GetTimeoutCompletionPercentage doesn't work

Discussion in 'Input System' started by RodGreen, Oct 29, 2021.

  1. RodGreen

    RodGreen

    Joined:
    Jan 11, 2020
    Posts:
    13
    Always returns 1.0. Seems to be sampling a different time than what's used to initialize the starttime
    Unity.InputSystem\Packages\com.unity.inputsystem@1.1.1\InputSystem\Actions\InputAction.cs : 1371
    Code (CSharp):
    1.  
    2. var duration = interactionState.timerDuration;
    3. var startTime = interactionState.timerStartTime;
    4. var endTime = startTime + duration;
    5. var remainingTime = endTime - InputRuntime.s_Instance.currentTime;
    6. if (remainingTime <= 0)
    7.    timerCompletion = 1;
    8. else
    9.    timerCompletion = (float)((duration - remainingTime) / duration);
    10.  
    when breaking into the code 'remainingTime' is something like -1200.0
    Looks like timerStartTime is an offset from some value whereas `InputRuntime.s_Instance.currentTime` is the current realtime value.

    Specifically timerStartTime is set by :
    Unity.InputSystem\Packages\com.unity.inputsystem@1.1.1\InputSystem\InputManager.cs : 3447
    Code (CSharp):
    1. var currentTime = m_Runtime.currentTime - InputRuntime.s_CurrentTimeOffsetToRealtimeSinceStartup;
    The fix is to fix the remainingTime calculation to use the same offset time value used for startTime
    Code (CSharp):
    1. var duration = interactionState.timerDuration;
    2. var startTime = interactionState.timerStartTime;
    3. var endTime = startTime + duration;
    4. var remainingTime = endTime - (InputRuntime.s_Instance.currentTime - InputRuntime.s_CurrentTimeOffsetToRealtimeSinceStartup);
    5. if (remainingTime <= 0)
    6.     timerCompletion = 1;
    7. else
    8.     timerCompletion = (float)((duration - remainingTime) / duration);
     
    Last edited: Oct 29, 2021
    NibbleByte3 and homemech like this.
  2. lookjaklook

    lookjaklook

    Joined:
    Oct 26, 2018
    Posts:
    6
    Man, thank you! I've been beating my head against the wall trying to figure out how to do a basic thing, like getting a hold percentage to show to the player a nice circular progress bar while he holds the button. I wasnt sure if that function was MEANT to do just that since it only showed either 0 or 1. Im shocked they haven't fixed it yet, do they not test their systems?
     
  3. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Fixed in upcoming 1.4.
     
    NibbleByte3 likes this.
  4. SiDavies

    SiDavies

    Joined:
    Feb 28, 2017
    Posts:
    1
    Anywhere when we can see when 1.4 is being released?
     
  5. AndrewAlexArt

    AndrewAlexArt

    Joined:
    Aug 23, 2019
    Posts:
    4
    Same quetion. Its about 6 months already without update and solving the problem. Or update package manager, because 1.4 already on GitHub
     
    ChichoRD likes this.
  6. Francoimora

    Francoimora

    Joined:
    Aug 1, 2013
    Posts:
    63
    For those like me who are waiting for 1.4 to be released for this bug to be fixed : it's already been released but you have to manually set it in the manifest because why using the Package Manager, hiding the updates from your users is so much fun ! Just replace "1.3.0" by "1.4.3" in the manifest.
     
    khan-amil likes this.