mouse.ViewSize different from camera.ViewportSize

To calculate some GUI position (0 to 1), I’ve seen a lot of examples telling to use the mouse.ViewSizeX and mouse.ViewSizeY to indicate the current screen dimensions.
However mouse.ViewSizeY shows a wrong screen dimension!
Here an example:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local mouseScreenSize = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
local cameraScreenSise = camera.ViewportSize	

print("mouseScreenSize: ", mouseScreenSize)
print("cameraScreenSize: ", cameraScreenSise)

Which shows:

mouseScreenSize:  1646, 596
cameraScreenSize:  1646, 668 -- << THE CORRECT Y SCREEN DIMENSION

Is this a Roblux Lua bug?

2 Likes

Pretty sure this is because of the top bar. Mouse.ViewSize most likely is cut off by the top bar, while camera.ViewportSize is not.

“This property [ViewportSize] ignores the GUI inset applied by the top bar…”

EDIT: After further reading, it seems like Mouse.ViewSizeY includes the space occupied by the top bar too, so I’m not sure.

Thanks for your reply.
In Mouse | Documentation - Roblox Creator Hub it says This length includes the space used by the topbar..
How it INCLUDES if the mouse.ViewSizeY < camera.ViewportSize.Y ?
And what’s the practical usage of mouse.ViewSizeY ?

Back in ye olde days Camera didn’t have a ViewportSize

https://web.archive.org/web/20121213203502/http://wiki.roblox.com/index.php/RBX.lua.Camera_(Object)

However mouse did have ViewSizeX/ViewSizeY

https://web.archive.org/web/20120710225557/http://wiki.roblox.com/index.php/RBX.lua.Mouse_(Object)

I imagine it’s a matter of backwards compatibility without any deprecation, rather than having a practical usage.

Interesting.
However at ViewSizeY (Property) - Roblox Wiki it says Size of the viewport’s Y in pixels. This is the height of the game window. which is not true…
So, is there any real application for mouse.ViewSizeY, once it doesn’t give the correct height of the game window?

We didn’t have a TopBar back then. Most of the UI was at the bottom of the screen instead.

ETA: When the top bar was introduced at first, unless you used offset and didn’t mind your content being covered by a semi-transparent black bar - you couldn’t show anything at the top of the screen, everything was simply pushed down 36 px when it came out.

So we can deduce that mouse.ViewSize is USELESS and has to be informed as a BUG?

Personally, I don’t think it’s worth it given we have an alternate method which works. It’s not useless as older and updated games will still use it.

72 is the difference in the Y heights, 72/2 = 36 which is the inset of the top bar. One is inclined to deduct it is perhaps purposely like that so older games still have the central mouse focus in the right point. Personally, I’d be more inclined to just ask for better documentation of it’s behaviour rather than as a bug.

1 Like

That’s fair.
Where can I suggest to Roblox a better documentation based on this case?

Documentation Issues - Developer Forum | Roblox is probably best

1 Like