Can we identify which binding of an action are fired?

Hi,

One thing I did with my action map is to allow both Mouse and Keyboard input to trigger the same Action, for example, Camera Zooming.

But now I realize Mouse Scroll and Keyboard Button Press behaves quite differently, and really we need to handle them differently, even though logically they are the same Action.

I wonder what Unity recommend here? Just create another Action to handle Mouse Scroll specifically? Or Can we identify which Binding fired in an Action event?

(I am using Input system with Unity Event, so all I get is a CallbackContext, which doesn’t seem to have any property about bindings.)

Thx!

1 Like

You can use the control property. This one isn’t really intuitive without the documentation, but there is a reason why they call it control (what you can find out if you read the InputControl page).

1 Like

OK thx, though looking at the InputControl and InputDevice class, I think they are likely not the best way to tackle my problem.

My actual problem is Mouse Scroll fire way too often under an uncapped framerate scenario. They were actually pretty fine at 60fps.

I don’t want to just ignore input (eg. wait until a certain amount of deltaTime), what other option do I have beyond just having a dedicated Action?

Do you do discrete action on scroll or something continuous? If you’re scrolling for example, when the event comes from the mouse scroll (use control property for identification) you can multiply the amount of scrolling with time.deltaTime so it becomes frame rate-independent.
If you do discrete action though (like switch weapon on scroll for example, or similar), you don’t really have any other choice but to detect when the last activation happened and only execute the next one if some time elapsed. Or you can switch the scroll to vector2 input and check the delta and do the change when the delta is big enough.

Use Camera Zooming as an example:

  • The mental model for this Action is continuous.

  • But the actual input from Keyboard (Press and hold a button) vs Mouse Scroll (High frequency small ticks) are very different from each other.

  • At high frame rate, a key hold is still a single action.performed, but Mouse Scroll is a lot of small actions.

  • Camera movement logic has acceleration and drag built in, and we already use deltaTime to make them framerate independent.

  • This doesn’t solve issue related to very small deltaTime and the difference between key hold vs scroll ticks.

I just lean towards a different Action at this point.

I don’t really understand the reason why don’t you define these as an Axis? I’m guessing you have two buttons and you have the Mouse Scroll Y. Both can behave like an Axis. So it would give you a “continuous” behavior. Just an idea.

I will try, I was using Value + Vector2, but technically I don’t need Scroll X.

I meant like this:
7612600--945883--screenshot.png

Zoom: action type: Value control type: Axis
Scroll/Y binding is just the mouse scroll Y binding
KeyboardZoom binding is 1D Axis composite with positive and negative