Get continuous Mouse ScrollWheel

In there Unity (legacy) Input System there are a few ways to get mouse scroll wheel input. For example:

Input.GetAxis("Mouse ScrollWheel")
Input.GetAxisRaw("Mouse ScrollWheel") // Unsmoothed data
Input.mouseScrollDelta.y

Each return float values of -1 to 1. GetAxis and GetAxisRaw may return values less than +/- 1 if sensitivity is less than 1.

I’ve tried Unity 2018.4 and 2020.1 with different Window 10 devices and mice and only get a single value when the mouse wheel is being scrolled.

How do I get a continuous stream of non-zero values while the scroll wheel is being moved?

Hi, sorry but I’m not getting what you’re asking for here. Are you not getting any value on a windows 10 system, or what?

All of the calls in your example code return a single value, and they only return non-zero values when the wheel is turned. So, I’m not sure why you make those points, because that is the way those calls behave. Do you want to alter those behaviors, somehow?

If you want a “stream” - if I understand what you mean - put the given call in an Update loop. You can couch your code in something like this so that you only respond to non-zero values:

float ScrollWheelChange = Input.GetAxis( "Mouse ScrollWheel" );
            if( Mathf.Abs( ScrollWheelChange ) > 0 ) {

I worked it out. The scroll wheel doesn’t return a value every frame that the scroll wheel is moving. This is different from how something like GetKey works or other input axis. I had to use a decaying value concept to simulate a similar behaviour.

1 Like