Search Unity

Feedback Feature Request: New InputAction event "Finished" to fire after Performed

Discussion in 'Input System' started by mafff, Oct 30, 2019.

  1. mafff

    mafff

    Joined:
    Jan 16, 2015
    Posts:
    16
    One feature that I think is missing and we need quite a lot is an event that fires when an action's phase changes from Performed to Waiting.

    The Cancelled event seems to be meant to fire only if the interaction ends abruptly before becoming Performed. There is no event that fires when the interaction ends normally. This is fine for interactions like Tap or Multi Tap, which end as they become Performed. With an interaction like Hold, however, the interaction can become Performed and end at different times.

    Suppose an action needs to be performed for as long as a button is held, but only if the button is initially held for t seconds. With the current system, I found no way of doing it with only one interaction on one Input Action, without some custom logic that would tie my components to the way the Input Action was set up in the editor.

    I ended up re-implementing the Hold interaction so that the Cancelled event is called after Performed, when the user released the button. This works for now, but is not consistent with how the other interactions work.

    What would make that use case much easier to handle would be a Finished event that fires when the phase changes from Performed back to Waiting. I think this would be a non-breaking change, and shouldn't be too difficult to implement.
     
  2. wuthrich7

    wuthrich7

    Joined:
    Apr 11, 2019
    Posts:
    7
    I was thinking about the same thing, for example, when moving an object while pressing the mouse button, releasing the button stops moving the object. Basically a handler (Callback) to inform you when the button stopped being pressed.


    Spanish
    Estaba pensando en lo mismo, por ejemplo, al mover un objeto estando el botón del ratón presionado, al soltar el botón deja de moverse el objeto. Básicamente un manejador que te informara cuando el botón dejo de ser presionado.
     
  3. wuthrich7

    wuthrich7

    Joined:
    Apr 11, 2019
    Posts:
    7
    In fact. How do I make a game like guitar hero. Working with hold interaction?.
    InputAction.action.triggered in Update, I suppose

    De hecho como hago un juego tipo Guitar Hero. Trabajando con Hold Interaction?
     

    Attached Files:

    Last edited: Jan 24, 2020
  4. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    43
    You can have more than one interaction per button. so you can have a 'hold' action as you say and also a 'press' action that is set to "press and release" and after the 'performed' part of your hold is done, you can check for the performed of 'press', which I think could be the 'finished' you're looking for.
    I'm actually just new checking this package out, so it's possible that the interactions don't work how i'd hoped. I'm just here looking for how to discern which interaction the callback is from

    EDIT: so it wouldn't be another interaction. it would just be another action mapped to the same button on button up
     
    Last edited: Jan 28, 2020
  5. mafff

    mafff

    Joined:
    Jan 16, 2015
    Posts:
    16
    @BinaryEclipse it's easy with simple press/release, but it start becoming tricky with more complex interactions like hold. There is no built-in interaction that performs when a button is released after t seconds. Of course you can write a custom interaction that would do almost the same thing as the hold interaction, but perform when the button is released. That's code duplication though.

    There are always multiple ways to make something work. The question is which one is the best way? I think the Input System can and should make this much simpler to achieve.
     
  6. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    43
    @mafff
    I'm saying that it works out the box already. press/hold for the simple stuff, and a second action that check for button release. In the callback, you handle knowing that the hold action had been performed prior
     
  7. mafff

    mafff

    Joined:
    Jan 16, 2015
    Posts:
    16
    @BinaryEclipse yes that would work. My suggestion is to add a Finished event so the same is achievable without creating an additional input action.