Please include a Hold duration property in CallbackContext

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.

Are you looking for the CallbackContext.duration?

1 Like

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…

Is there anything wrong with just polling the input to time how long it’s been pressed?

1 Like

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.

1 Like