Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug Scaled SceneView width and height

Discussion in 'Editor & General Support' started by Epsilon_Delta, Oct 27, 2020.

  1. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    266
    Hello,

    Code (CSharp):
    1. SceneView.currentDrawingSceneView.camera.scaledPixelHeight
    gives me the same value as
    Code (CSharp):
    1. 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?
     
  2. virtualjay

    virtualjay

    Joined:
    Aug 4, 2020
    Posts:
    68
    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.
     
    Epsilon_Delta likes this.
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,558
  4. virtualjay

    virtualjay

    Joined:
    Aug 4, 2020
    Posts:
    68
    Thanks for the pointer. This seems to give the same value.
     
    adamgolden likes this.
  5. michaelday008

    michaelday008

    Joined:
    Mar 29, 2019
    Posts:
    135
    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.
     
    adamgolden likes this.