Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Feature Request Please include a Hold duration property in CallbackContext

Discussion in 'Input System' started by pioj, Nov 29, 2023.

  1. pioj

    pioj

    Joined:
    Nov 5, 2012
    Posts:
    34
    I was hoping the Input System would ease the way we handle long presses and combo attacks for fighting games.

    Instead, we keep having to rely on different event phases to tell how much time a button is being pushed.

    Can we at least have a default predefined variable in the API for such cases, please?

    I know about other 3rd party Assets, but I 'd like to keep as stock as possible.
     
  2. Are you looking for the CallbackContext.duration?
     
    pioj likes this.
  3. pioj

    pioj

    Joined:
    Nov 5, 2012
    Posts:
    34
    mmm thx Lurking-Ninja, but it's not quite what I'm looking for:
    • CallBackContext.duration reports 0 when no Hold is set in the Interaction panel.
    • The Hold Interaction seems to be mandatory for timers to start from.
    • duration appears to be directly linked to Hold.time setting in the Interaction panel.

    It may serve my initial objetive for simple holding events, but if I'd ever wanted to feature a variable height Jump mechanic (mostly 2D platformers), the character should always jump, no matter how much time I'm pressing the button.

    The amount of force applied for the jump is what (I think) will be modified by CallBackContext.performed. For single values it's fine, but I may end having to stack multiple Hold Interactions...
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,795
    Is there anything wrong with just polling the input to time how long it's been pressed?
     
    pioj likes this.
  5. Yes, there is no meaning of a timer when you have immediate controls. When the
    performed
    event and the
    started
    event are firing at the same time, duration is obviously zero. It wouldn't make sense any other way. If you need custom behavior, you will need to develop it. It's not too complex, just record the
    CallbackContext.time
    in the start event and record whenever you feel you have to fire an event and subtract the recorded time from the latest
    CallbackContext.time
    and you get a duration (in
    cancelled
    event for example).
    If you're custom pooling you can do it with
    Time.realtimeSinceStartup
    or something.
     
    pioj likes this.