Search Unity

BUG: GUIUtility.GUIToScreenPoint and ScreenToGUIPoint both don't do anything

Discussion in 'Immediate Mode GUI (IMGUI)' started by mischa2k, Jan 17, 2016.

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I attached a simple project with 10 lines of code that shows how GUIUtility.GUIToScreenPoint and ScreenToGUIPoint are always equal to Input.mousePosition. This is probably a bug because one of those functions should convert the y coordinate to Screen.height-Input.mousePosition.

    Subtracting it from Screen.height is needed if (for example) we want to show a label next to the cursor. Right now we always have to do:
    Code (CSharp):
    1. Vector2 guiPos = new Vector2(Input.mousePosition.x, Screen.height-Input.mousePosition.y);
    2. GUI.Label(new Rect(guiPos.x, guiPos.y, width, height), "Text");
    But this should be the easy way to do it:
    Code (CSharp):
    1. Vector2 guiPos = GUIUtility.ScreenToGUIPoint(Input.mousePosition);
    2. GUI.Label(new Rect(guiPos.x, guiPos.y, width, height), "Text");
    Any insight on this would be greatly appreciated!
     

    Attached Files:

  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Yes, it doesn't do anything. The demo project that I attached converts the mouse position with the 2 functions all the time, but it shows the same results no matter where you move the mouse. I expected one of those function to do the Screen.height-mouse.y thing, but none of them does.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282