GetTimeoutCompletionPercentage doesn't work

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

var duration = interactionState.timerDuration;
var startTime = interactionState.timerStartTime;
var endTime = startTime + duration;
var remainingTime = endTime - InputRuntime.s_Instance.currentTime;
if (remainingTime <= 0)
   timerCompletion = 1;
else
   timerCompletion = (float)((duration - remainingTime) / duration);

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

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

var duration = interactionState.timerDuration;
var startTime = interactionState.timerStartTime;
var endTime = startTime + duration;
var remainingTime = endTime - (InputRuntime.s_Instance.currentTime - InputRuntime.s_CurrentTimeOffsetToRealtimeSinceStartup);
if (remainingTime <= 0)
    timerCompletion = 1;
else
    timerCompletion = (float)((duration - remainingTime) / duration);
2 Likes

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?

Fixed in upcoming 1.4.

1 Like

Anywhere when we can see when 1.4 is being released?

Same quetion. Its about 6 months already without update and solving the problem. Or update package manager, because 1.4 already on GitHub

1 Like

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.

1 Like