Search Unity

How to know if i'm pressing or releasing

Discussion in 'New Input System' started by Zelop, Jan 27, 2019.

  1. Zelop

    Zelop

    Joined:
    Jul 28, 2016
    Posts:
    8
    Hi,
    Firstly : sorry for my english, it's not my natural langage.

    I don't understand how the press and release input works.
    How do i know in my handler function if i'm pressing or releasing my button ? For example, if i want to jump with space, and stop the jump by releasing space : how do i know in my handler Jump() if I'm pressing or releasing the input ? I know we can use a "context" as argument, but I don't understand how that's work.. Should I use this context ? if yes, how do I do ? else what I need to use ?
     
  2. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    20
    Use .ReadValue<float>() оf your CallbackContext
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,286
    There's context.started and context.performed. "Started" is when you press, "Performed" is when you release.
     
  4. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    754
    There's a change to how this works coming in the next package.

    As of 0.1.2-preview, there's no great way for this. Basically, it's down to ReadValue<float>() as @Elhimp mentions. Even PressInteraction or PressAndReleaseInteraction don't really solve the problem.

    As of the upcoming 0.1.3-preview, the default interaction model (i.e. when you have no interaction explicitly added to a binding) is changing. Where before, every value change resulted in a call on `performed`, now what happens is that `started` and then `performed` gets triggered when the control is being actuated and `cancelled` is triggered when the control stops being actuated. I.e. close to what @Baste describes.

    So, going forward, this will be very simple. `started` and then `performed` when the button goes down and `cancelled` when the button goes up. And if you have the continuous flag on, you'll get another `performed` every frame while the button is down. And works the same way regardless of the type of control. If you have a stick, for example, you'll get a `started` and `performed` when the stick moves out of the deadzone and a `cancelled` when it moves back into it.
     
  5. Zelop

    Zelop

    Joined:
    Jul 28, 2016
    Posts:
    8
    Ok thank you for all answers, I'll try