Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is the document of Rect so confuse ?

Discussion in 'Documentation' started by kactus223, Jun 19, 2017.

  1. kactus223

    kactus223

    Joined:
    May 20, 2014
    Posts:
    35
    I've learnt and work with Unity for over 3 years, and have done some small games. But recently I have found out that all I known about unity's Rect is wrong. I read the document of Rect several times, and all I notice is the figure show me Rect's 4 most important params: x, y, width, height. As you can see on the figure, (x,y) is the top-left point of the rect. So everytime I create a new Rect, I always parse top left point's coordiate as x and y parameters. But I was wrong, (x,y) is actually bottom-left. It's just so embarassing that I don't know that until now. Is there anyone else got confuse like me, or is the document of Rect so confuse ?

     
    visca_c likes this.
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's both top-left and bottom-left. The docs say that straight out; read the second paragraph again. It's arbitrary and depends on the context...there's nothing inherent that makes it one or the other. It could even be top-right or bottom-right, if you wanted it to be.

    --Eric
     
  3. visca_c

    visca_c

    Joined:
    Apr 7, 2014
    Posts:
    30
    I second this. When I tried to work with RectTransform.rect, I assumed it would be bottom left, but the documentation's illustration confused me into believing it's top left, then I did some debugging and it turns out to be bottom left. It would be nice if the documentation shows two sets of images with more clear titled sections.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    It's not bottom left. It's just four floats - the x/y coordinates and the width/height. The x and y isn't relative to anything, it's just numbers.

    It's kinda like how a Vector3 can represent both a point in world space, or a point relative to some object, or a velocity.


    So the space the rect is in is not a part of the abstraction. The RectTransform has a rect that's "in the local space of the Transform" . The GUILayout system has rects that are relative to the drawing window's upper left.


    The documentation that's actually bad is the RectTransform.rect docs, because "in the local space of the transform" is pretty vague. It's also just fantastic that the UGUI example uses OnGui for data readouts.