Scaled SceneView width and height

Hello,

SceneView.currentDrawingSceneView.camera.scaledPixelHeight
gives me the same value as

SceneView.currentDrawingSceneView.camera.pixelHeight

even if the scene view is on 150% scaled monitor. I cannot properly clamp position to sceneview because of this (It is working fine on 100% scaled monitor). I think this is a bug. Is there any way to get current UI scaling of the editor window?

I’ve run into this as well. Oddly enough, your post is the only one I’ve found mentioning anything similar.

In my case, I had some IMGUI code that was putting buttons/labels on the screen view. This worked fine, until I connected into this machine with Remote Desktop from a machine with a much higher resolution. RD automatically changes the DPI on the remote display when you do this. So when I was connected with RD, things would plot in the wrong places. I verified this by putting labels every 100 pixels on the x and y axes.

Unity didn’t handle this well in 2019 LTS, 2020 LTS or 2021. Camera.pixelWidth/pixelHeight were always the same as Camera.scaledPixelWidth/scaledPixelHeight. Oddly enough, does update Screen.dpi to be the proper dpi.

My workaround is to use to use a scaling factor = 96 / Screen.dpi. Then you can multiply pixelWidth/Height by that to get the proper scaled Width/Height. You can also multiply your x/y coords by that to get the right location. I would have expected either pixelWidth/Height or scaledPixelWidth/Height to have taken this into account so you could properly use one or the other.

Hopefully this post will help someone else out that lands here.

1 Like

I had a similar issue with screen scaling, EditorGUIUtility.pixelsPerPoint multiplier worked for me:

https://docs.unity3d.com/ScriptReference/EditorGUIUtility-pixelsPerPoint.html

5 Likes

Thanks for the pointer. This seems to give the same value.

1 Like

This post saved me a lot of trouble. I had a similar issue with a GUILayout.Box() call displaying the box on the wrong spot on the screen when someone had a 4k monitor with Windows display scaling set to 150%.

Dividing the x, y, width, and height values by the EditorGUIUtility.pixelsPerPoint value ensured that it worked perfect in any scale, since that value is just 1 on a monitor with 100% scale.

1 Like