I’m struggling with a bug in my app, where mouse positions are reported incorrectly when the game is in full-screen mode. I think I’m looking at a Unity bug, but if somebody can explain to me how this is correct behavior (or how to work around it in any case), I would be very grateful.
My player settings are set up as follows:
As you can see, I support only a 4:3 aspect ratio. So when I full-screen the app on my MacBook Pro, it gets letterboxed on left and right, as shown below. Note that the beige frame shown extends all the way to thet edges of the screen-space Canvas.
OK so far. But here’s the problem: Input.mousePosition reports 0,0 at the lower-left corner of the screen, i.e., the black area left of the actual drawing area; and it reports 1024,768 in the upper-right corner of the screen (i.e. the black bar on right). Note that the values reported don’t even match the aspect ratio of the screen they’re reporting. They also have no relationship I can figure to the positions of things in the game view.
Screen.width and Screen.height, as well as Camera.pixelWidth and Camera.pixelHeight, which all report 1024 x 768. (EDIT: even Screen.currentResolution reports 1024 x 768 while in full-screen mode.) This seems to (correctly) reflect the 4:3 aspect ratio of the area I’m actually drawing. But, again, it does not reflect whatever weird thing the reported mouse position is doing.
What the mouse appears to be doing is getting its coordinates relative to the physical screen, and simply scaling that to the width and height of the virtual display. And that seems like an incorrect thing to do to me. It’s supposed to be in screen coordinates (or so I believe), but it is not.
Can anyone confirm or deny this bug? And, anybody see a way I can compensate or work around it, to figure out where on my virtual (not physical) screen the mouse is pointing?