Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug UIElements top position is off

Discussion in 'UI Toolkit' started by juhaelee, Aug 16, 2020.

  1. juhaelee

    juhaelee

    Joined:
    Apr 1, 2015
    Posts:
    8
    Unity Version: 2020.1.2f1
    Unity UI Toolkit version: Version 1.0.0-preview.6

    I am trying to absolute position my UIElement using code, but noticed that the position is off. I decided to test it manually, here are the steps I took:

    1) Calculate the world coordinates:
    Code (CSharp):
    1.  
    2. float height = Camera.main.orthographicSize * 2.0f;
    3. float width = height * Screen.width / Screen.height;
    4. Vector2 worldSize = new Vector2(width, height);
    5. Vector3 worldPosition = new Vector3(-width / 2, 0);
    6.  
    7. Rect rect = RuntimePanelUtils.CameraTransformWorldToPanelRect(wholeWidget.panel, worldPosition, worldSize, Camera.main);
    8. Debug.Log("rect: " + rect);
    From this I got that the world height is 639.00px:
    Screen Shot 2020-08-16 at 12.36.23 PM.png

    2) I set my UI element to have an absolute position and the top to 639px. Correct me if I'm wrong, but my element should appear at the very bottom? Instead, there is some lingering space:

    Screen Shot 2020-08-16 at 12.36.50 PM.png

    3) I tried using bottom: 0px instead, and that worked as intended:
    Screen Shot 2020-08-16 at 12.37.18 PM.png

    My question is, why doesn't the top:639.00px: work correctly? I measured the size of the game screen and it was indeed 639px.
     
  2. juhaelee

    juhaelee

    Joined:
    Apr 1, 2015
    Posts:
    8
    Nm, I think I may have figured it out. It was due to the scale mode of my panel