When did Unity change the beaviour of Event.delta for mouse wheel?

I’ve just noticed that when you press shift and move the mouse wheel, the delta.y value is actually swapped and becomes the delta.x value.

eg you have (0, 3) when you move the wheel and you have (3, 0) when you hold shift and use the wheel.

When was that introduced? The issue I’m having with the shift key is in 2022.3.16f1.

Example code:

using UnityEngine;

public class MouseWheelTest : MonoBehaviour
{
    public void OnGUI()
    {
        if (Event.current.type == EventType.ScrollWheel)
        {
            Debug.Log(Event.current.delta);
        }
    }
}

What’s the proper solution for this breaking change?

I guess that was introduced to simulate horizontal scrolling while only having a vertical scroll wheel.

That’s unlikely to generate useful information, even if the dude who did it came in and said “I made that change in commit 244feb4 on May 1, 2023.”

When existing API behavior changes, think of it in terms of what might have happened:

  • you misread the original behavior
  • you are misreading the current behavior
  • something (such as the execution order) changed and revealed a bug in your design
  • you introduced another bug (or inadvertently damaged your project) that causes this inconsistent behavior
    —> this could be something in your operating system that changes how mouse is filtered, for example
  • Unity released something with an actual bug (divergence from documentation)
  • Unity changed something in their API intentionally

The only way to figure out what has happened above is for you to isolate, isolate, isolate.

Isolate everything and make a single tiny micro script that PROVES the behavior is as you believe it to be.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If you can prove a bug in Unity’s release, that’s AWESOME… file a bug!

Help → Report A Bug.

Report one bug at a time with all the expected supporting information attached.

And finally, don’t hold your breath for the bug to be fixed. YES, it might be, but it might require you to implement a work-around in the meantime. As annoying as that is, that’s just what we chickens using someone else’s game engine must deal with. :slight_smile:

It is, because from then on my asset broke and I have to add the scripting define symbols accordingy :wink:

However, the change makes sense if it was to allow horizontal scrolling for a vertical scroll wheel. So I coded around that problem. So the shift / scroll wheel combination I’m catching just evaluates around x or y not being zero and picks the one that’s not zero.

Ugh, I feel your pain… I hate little “warts” like this that we have to put in our code. The worst is warts that end up causing bugs later when the original fault is fixed.

About the only suggestion I have is to hope they mentioned it in one of the release notes.

Otherwise I guess the drill would be to bisect back through historical versions of Unity. But your fix sounds smart enough that it would work new or old, if I understand what you wrote here:

It’s also possible that they even originally conceived of 2D scroll wheels but implemented it broken, so when they fixed it technically the docs don’t need to be fixed. Sigh.

1 Like

Yeah, I left a comment in the Unity API docs. Unity should update it accordingly, ie that the shift key swaps x and y when the scroll wheel is being used.

Looks like this was added for Windows in 2023.3.0a1, 2023.2.0b6, 2023.1.10f1, 2022.3.7f1 and 2021.3.30f1. This was a bugfix to match macOS behaviour, as on Mac holding shift will make the vertical scroll wheel behave like a horizontal one.

2 Likes

I don’t get why an OS that has a small marketshare and is know to not be used for videogames can become the standard on windows which has 72% marketshare

2 Likes

I initially posted that I thought this was dumb too (and in most cases I still think it is) but after posting I realized I didn’t know the default behavior for holding the shift key while scrolling on Windows and my search results claim it’s not an actual thing. If it is and the search is wrong I’d love to know.

I don’t know about your search results but I checked in a few applications like Notepad++, Visual Studio and Firefox and they all seem to treat Shift + scroll wheel as horizontal scroll. So it isn’t like this behaviour isn’t unheard of on Windows.

I think this behaviour really helps usability in the editor as most people don’t have mice with horizontal scroll wheel and there are plenty of places in Unity where you need to scroll horizontally.

4 Likes

wait? so this is not an ingame behaivour? only editor?

then i get my previous post back. the few windows owned apps I’ve checked don’t have this behavior. but they use the ctrl to change the scrool behaviors.

or the browsers, firefox do it but is hard to check both for firefox and other browsers because they switch to mobile mode if you tryt to make the window less wide to get the scroll bars

It’s the behaviour of UI in both editor and runtime (UnityEngine.Event is only meant to be used as input for UI). If you query input from the input system directly, it will not do this.

9853440--1418769--8rbuf2.jpg