Search Unity

Bug with Windows Scaling?

Discussion in 'Editor & General Support' started by MvNimwegen, Feb 14, 2022.

  1. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    56
    Hi,

    I am trying to report an issue through the Unity Hub Bug Reporter, but this doesn't seem to work (which it did previously) ironically... That's why I am posting this here.

    I am experiencing, what I believe to be, a bug regarding Windows Scaling.

    What I am trying to do it project world points onto the scene view (
    Vector3
    to
    Vector2
    ). Then I use these coordinates to draw GUI onto the scene view (in my case
    GUI.button
    ). If Windows GUI scaling is set to 100%, all is well. If you set it to anything else, these values to not map anymore. This is mostly a problem on 4K screen, on which the GUI scale is usually >100%.

    Here is a clip of the behaviour at 100% scale (right) and 150% scale (left).
    firefox_6a0ct7FURY.gif

    This piece of code can reproduce the problem:
    Code (CSharp):
    1. //Get screen position
    2. Vector2 screenLabelPosition = (Vector2)SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(Vector3.zero);
    3.  
    4. //Draw button
    5. GUI.Button(new Rect(screenLabelPosition.x, Screen.height - screenLabelPosition.y, 100f, 20f), "SomeText", GUI.skin.label);
    6.  

    Do this with Windows scaling at 100%, then at for example 150% and see the difference.
    ApplicationFrameHost_WNn2VClZLQ.png

    The WorldToScreenPoint does take the GUI scaling into account, the drawing of the Button however does not. As such, these two values do no longer map correctly.

    Does anybody else have this issue? Do you know how to get around this?
    I could play with settings like DPI to detect the scale, but I suspect this could introduce other bugs elsewhere.
    What are your thoughts?

    Thanks! :)
     
  2. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    56