InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

Disabling/Enabling an InputAction doesn't reset it's state.

Open Wahooney opened this issue 8 years ago • 10 comments

There is an issue in 0.0.7/8 when you have a Press and Release InputAction (in my case a member, not an asset):

  1. Press the key
  2. Disable the InputAction
  3. Release the key
  4. Enable the InputAction
  5. The next press of that key doesn't fire the InputAction::started event (presumably because it's being held in some sort of buffer of pressed buttons).

Wahooney avatar Sep 26 '18 09:09 Wahooney

Has there been any movement on this issue? I'm on 0.1.2 and it's still a problem. Any work arounds?

BTW the SetCallbacks() with the and Generate Interfaces is pretty sweet.

Wahooney avatar Jan 16 '19 21:01 Wahooney

Has there been any movement on this issue? I'm on 0.1.2 and it's still a problem. Any work arounds?

I'll take a look, and try to get a fix in for next release

douglas-piconi avatar Jan 16 '19 21:01 douglas-piconi

Has there been any movement on this issue? I'm on 0.1.2 and it's still a problem. Any work arounds?

I'll take a look, and try to get a fix in for next release

Fantastic! Thank you!

Wahooney avatar Jan 16 '19 21:01 Wahooney

@Wahooney I'm going to talk over with a few other engineers. When I wrote up a test to repro your issue, I'm starting to think it might be as designed. But I could be wrong, I'm gonna get a second opinion. Here is a test without any disabling. Press the key, action gets fired, release the key, different action gets fired. Press the key, action gets fired. If you comment out releasing that key, the action wont get fired twice. I'm wandering if the key is also released while action is disabled, is that as if it never happened, as in below if that code was not there to release. I'll get back to you, this one I'm not 100% clear on what should actually happen.

    var keyboard = InputSystem.AddDevice<Keyboard>();
    var action = new InputAction();
       action.AddCompositeBinding("Dpad")
            .With("Up", "/<Keyboard>/w");

    action.Enable();

    Vector2? value = null;
        action.performed += ctx => { value = ctx.ReadValue<Vector2>(); };

    // Press the Key
    Assert.That(keyboard.wKey.isPressed, Is.False);
    InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.True);

    Assert.That(value, Is.Not.Null);
    Assert.That(value.Value, Is.EqualTo(Vector2.up));

    // Release the Key
    value = null;
    InputSystem.QueueStateEvent(keyboard, new KeyboardState());
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.False);
    Assert.That(value, Is.Not.Null);
    Assert.That(value.Value, Is.EqualTo(Vector2.zero));
    
    // Press the Key Again
    value = null;
    InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.True);
    Assert.That(value, Is.Not.Null);
    Assert.That(value.Value, Is.EqualTo(Vector2.up));

douglas-piconi avatar Jan 17 '19 20:01 douglas-piconi

@Wahooney This test is what I interpret your issue, but this passes. Is there anything I'm missing here on what you are running into?

    var keyboard = InputSystem.AddDevice<Keyboard>();
    var action = new InputAction();
       action.AddCompositeBinding("Dpad")
            .With("Up", "/<Keyboard>/w");

    action.Enable();

    Vector2? value = null;
        action.performed += ctx => { value = ctx.ReadValue<Vector2>(); };

    // Press the Key
    Assert.That(keyboard.wKey.isPressed, Is.False);
    InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.True);

    Assert.That(value, Is.Not.Null);
    Assert.That(value.Value, Is.EqualTo(Vector2.up));

    action.Disable();

    // Release the Key
    InputSystem.QueueStateEvent(keyboard, new KeyboardState());
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.False);
    
    action.Enable();
    
    // Press the Key Again
    value = null;
    InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
    InputSystem.Update();
    Assert.That(keyboard.wKey.isPressed, Is.True);
    Assert.That(value, Is.Not.Null);
    Assert.That(value.Value, Is.EqualTo(Vector2.up));

douglas-piconi avatar Jan 17 '19 20:01 douglas-piconi

If I'm reading that right that does seem to be the process. I'll start a new project and make a minimal example, I'll let you know what I find.

Wahooney avatar Jan 23 '19 16:01 Wahooney

@Wahooney There's a stack of changes that landed yesterday and among them, I think the issues around this should be resolved.

One of the key changes is that actions will now properly cancel ongoing interactions when calling Disable (see here).

When reenabled, there is also now an initial sync to the current state of the control. And subsequent control changes should lead to proper triggering.

Please let us know if you still see issues around this.

Rene-Damm avatar Jan 23 '19 18:01 Rene-Damm

@Wahooney , with 0.2.0-preview now available. You should be good now with this issue being fixed. I'll keep bug open until you can confirm.

douglas-piconi avatar Feb 20 '19 20:02 douglas-piconi

@douglas-piconi This issue is fixed somewhere in the past and does not happen anymore. I closed the FB side and think it is good to close it here as well.

JiaUnity avatar Feb 20 '19 21:02 JiaUnity

ok great thank you @JiaUnity

douglas-piconi avatar Feb 20 '19 21:02 douglas-piconi