Search Unity

Learning new InputSystem - when and how is the Cancelled callback used?

Discussion in 'Input System' started by Reverend-Speed, Sep 14, 2020.

  1. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    Hey folks, I'm working my way through the new input documentation and tutorials, most of which seems fairly clear. However, I'm a little confused by the fifth of the Action callbacks,

    Disabled, Waiting, Started, Performed, Canceled

    • Disabled and Waiting seem fine, I can handle those with OnEnable and OnDisable.

    • 'Started' makes sense, it's the point at which the interaction begins. GetButtonDown, if you will.

    • Performed is for when the interaction has ended. GetButtonUp seems similar.
    Cancelled, however - I'm at a loss, at least for keyboard and gamepad inputs. I suppose this could be like clicking or tapping on a gui button and then, instead of releasing, dragging your finger off the icon and then releasing. Is this what it refers to?

    I'm sorry about the confusion, I just keep thinking of the term 'cancelling' in a fighting/brawler game context, where that would imply initiating a punch, for example, only to 'cancel' it by choosing a different action (eg. jump) before the punch animation reaches the critical impact point, thus acting as a feint and a means for high-level players to creatively mix up attacks and react to situations.

    Am I anywhere near the right answer on this? Can somebody illuminate me? Much obliged!
    (Also, is there an equivalent of GetButton (as in, the button is held)? I notice the settings for the Input System Package has a field for Default Hold Time, but I haven't encountered examples of this yet (early days))
     
    FlightOfOne and RunninglVlan like this.
  2. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    40
    That depends entirely on how you have your Action Type and Interactions, I did some extensive testing, literally today and here is what I've come up with:

    Based on your Interaction set up of your Action these events are fired at different times.

    Action Type Button
    Interaction None
    started, performed on button down | canceled on release

    Interaction Press And Release
    started, performed on button down | started, performed again on button up

    Interaction Press Only
    started, performed on button down

    Interaction Release Only
    started on button down | performed on button up

    Interaction Hold
    started on button down | performed once the button is held long enough | canceled when the button is released too early

    Interaction Multi Tap
    started on button down | canceled if button not pressed fast enough soon enough | performed if button pressed enough times fast enough
    note: multitap doesn't work

    Interaction Slow Tap
    started on button down | canceled if you release before min tap duration | performed as soon as you release if the alotted min tap duration has elapsed (happens when you release the button not when the time has elapsed)

    Interaction Tap
    started on button down | performed if you release before the Max Tap Duration | canceled if you hold down past the Max Tap Duration as soon as the duration passes(no event on button up)

    Action Type Value
    Control Type Any, Analog, Axis, Bone, Digital, Double, Dpad, Eyes, Integer, Quaternion, Stick, Touch, Vector2, Vector3
    Interactions None
    started, performed on button down | canceled on button up

    ControlType Any, Analog (didn't test the rest but assume it is the same)
    Interactions Press And Release
    started, performed on button down | performed, canceled on button up

    Interactions Press Only
    started, performed on button down | performed, canceled on button up

    Interactions Release Only
    started on button down | performed, canceled on button up

    Interactions Hold
    started on button down | performed after hold time | canceled when stopping game
    note: this seems broken can't get any more actions, it's like it never releases

    Interactions Multi Tap
    started on button down | performed if button is pressed enough times fast enough | canceled if button is not pressed fast enough soon enough
    note: doesn't work it's broken, only get started and canceled no matter what

    Interactions Slow Tap
    started on button down | performed on release if button was held long enough | cancelled on release if button was not held long enough

    Interactions Tap
    started on button down | canceled as soon as Max Tap Duration elapsed | performed if released before Max Tap Duration elapsed

    Action Type Pass Through
    Interactions None
    performed on button down | performed on button up

    Interactions Press and Release
    started, performed on button down | canceled on button up

    Interactions Press Only
    started, performed on button down | canceled on button up

    Interactions Release Only
    started on button down | performed, canceled on button up

    Interactions Hold
    started on button down | performed as soon as hold time elapses | canceled on button up

    Interactions Multi Tap
    started on button down | performed if button pressed enough times fast enough | canceled if button is not pressed enough times fast enough
    note: This seems to be the only multi tap that is actually working

    Interactions Slow Tap
    started on button down | performed on button up if Min Tap Duration elapsed | canceled on button up if Min Tap Duration not elapsed

    Interactions Tap
    started on button down | performed on button up if release before Max Tap Duration | canceled as soon as Max Tap Duration elapsed (no event on button up after Max Tap Duration elapsed)
     
  3. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    @FileThirteen - Thanks so much for that research. I've actually come across this page which seems most enlightening. I think I have a fairly good idea of what use Started, Performed and Cancelled are intended for now, but I'll pour over your research with greedy interest! =D
     
  4. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    40
    That is rather interesting, that's kind of exactly what I was looking for lol. But my results tell you very specific stuff like on release vs after the time elapsed and such. Still a useful page, also I think mine is easier to read, I know it's not very pretty, it would look nicer on a google sheet or something, but it's plain english vs the control magnitude stuff on that doc. Besides that some of the interactions don't seem to work as intended and also I give more detail on what exactly happens at each part, some things are a bit unexpected, like Release Only, started on button down, performed on button up. Rather than started on button up, performed on button up which is how I would have assumed it would work based on all the other interactions.
     
    Reverend-Speed likes this.
  5. GoodArcade

    GoodArcade

    Joined:
    Aug 7, 2013
    Posts:
    7
    So interestingly enough, Vector2 will think input is cancelled if I press W then, without letting go of W, press S as well. Is there a work around to avoid this weirdness?
     
    bodhi_berry and Aztecslayer like this.
  6. Aztecslayer

    Aztecslayer

    Joined:
    Oct 19, 2013
    Posts:
    1
    That´s exactly my problem, did you find a solution?
     
  7. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Sounds like we need to modify how actions read vector2, because W+S is definitely actuated even if vector2 is (0, 0)
    @GoodArcade would you mind to file a bug report for this? Thanks a lot!
     
    bodhi_berry likes this.
  8. astulb

    astulb

    Joined:
    Sep 5, 2018
    Posts:
    3
    @dmytro_at_unity I am also having this issue and I see it is still present on the current version of the input system, can you give us an approximation on how long until this gets fixed? thanks!
     
    siliconkgk likes this.
  9. Anttt

    Anttt

    Joined:
    Nov 8, 2021
    Posts:
    1
    Is there any combo of Interactions equivalent to started when pressed, performed while pressed and canceled when released. I'm using the 1.0.2 version of InputSystem.

    Context is I'm trying to replace a control system based on the old inputs (GetKey, etc) without changing the code beyond the actual input reference if possible. So what I want is basically a GetKey, GetKeyDown and GetKeyUp equivalent.
     
  10. landosilva

    landosilva

    Joined:
    Oct 23, 2014
    Posts:
    5
    Does anyone has an update on this? That's exactly my problem at the moment. I want to trigger one event only when there is no more Vector2 Input, but right now there is no such thing. If I press/release S while holding W it will dispatch events. I'm using Input System 1.3.0.
     
    Mesa-The-Aalfa and bodhi_berry like this.
  11. zajacignacy

    zajacignacy

    Joined:
    Nov 24, 2021
    Posts:
    2
    So actually i used two actions: Drag with Vector2 value, and tap (button) like this,

    private void Tap_canceled(InputAction.CallbackContext context)
    {
    if (currentPosition.sqrMagnitude > 0)
    {
    OnDragEnded?.Invoke(currentPosition);
    }
    }
    private void Drag_performed(InputAction.CallbackContext context)
    {
    currentPosition = context.ReadValue<Vector2>();
    }

    works for me.
     
  12. bodhi_berry

    bodhi_berry

    Joined:
    Feb 13, 2017
    Posts:
    8
    Hi! Is there any update on when this will be fixed or a good workaround in the mean time? I'm currently facing this issue with version 1.3.0 and it's holding me back from finishing my character controller. Thanks!
     
  13. Rouddem

    Rouddem

    Joined:
    Dec 15, 2015
    Posts:
    14
    I can't believe such basic bugs can still persist years later... Bug present in version 1.6.3.
     
  14. wannaMakeAGame

    wannaMakeAGame

    Joined:
    Dec 7, 2020
    Posts:
    49
    Does anyone know can we add time bias to canceled event? I mean if the buttons are pressed again after release in short period the canceled event won't run?