InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

[0.9.2-preview] ReadValue() using polling API for button always return 0

Open SKroell opened this issue 7 years ago • 2 comments

In an attempt to fix the game breaking issue found in #663 and #677 I thought that maybe the polling API didn't suffer from the stuck key bug. Following the documentation I set up a button InputAction and simply read it in Update() using the code below. But for some reason it always return 0, doesn't matter if the key is pressed or not. Checking .triggered returns correctly and same for the performed callback. Am I missing something?

public class InputTest : MonoBehaviour {
    private TestInput testInput;
    void Start() {
        testInput = new TestInput();
        testInput.Enable();
    }

    void Update() {
        Debug.Log(testInput.actionMap.action.ReadValue<float>());
    }
}

input

SKroell avatar Aug 14 '19 18:08 SKroell

Hey @SKroell !

I have the issue and I can bring some logs, I don't know if you'll learn anything new but I described my case here : https://github.com/Unity-Technologies/InputSystem/issues/663#issuecomment-522640640

Thanks a lot !

MistyGriotte avatar Aug 19 '19 16:08 MistyGriotte

In an attempt to fix the game breaking issue found in #663 and #677 I thought that maybe the polling API didn't suffer from the stuck key bug. Following the documentation I set up a button InputAction and simply read it in Update() using the code below. But for some reason it always return 0, doesn't matter if the key is pressed or not. Checking .triggered returns correctly and same for the performed callback. Am I missing something?

This is expected. At least with how the API currently works.

The way this is set up, ReadValue<T>() reads the current value WHILE the action is in progress. It does so by simply querying the current control that is driving the action (there is none if the action is waiting for input) and returning its current value. If the action is not currently in progress, it will simply return default(T).

This works best with Value-type actions but even with Button actions (or Pass-Through actions, for that matter), it will return 1 while the button is held down.

Now the thing is that in your case there's a Press interaction on the binding. Set to PressAndRelease, the action will start&perform on press and start&perform on release. This means that outside of those small windows in time, the action will always be in waiting state and thus returns 0.

Rene-Damm avatar Aug 19 '19 16:08 Rene-Damm