1
\$\begingroup\$

Normally when anchors are on the same position, we can use .sizeDelta or .rect.width/height from RectTransform, but if the anchor are stretched, both of them returns negative values:

normal inspector debug inspector

Which in reality is not 5 in size at all: real button size on the canvas

There are already SetSizeWithCurrentAnchor but how to get other's RectTransform's absolute size?

\$\endgroup\$
6
  • \$\begingroup\$ What exactly does .rect equal? \$\endgroup\$
    – Ed Marty
    Commented Feb 13, 2019 at 14:13
  • \$\begingroup\$ Also, what does that screenshot show? I don’t see the RectTransform tool’s four blue handles which would show how big it is. \$\endgroup\$
    – Ed Marty
    Commented Feb 13, 2019 at 14:15
  • \$\begingroup\$ .rect.width shows -900, .rect.height shows -5, it doesn't show because i'm using panning tool instead of resize tool, but the real size is really should be as big as the picture above (not -5, not -900, about 180 x 150-ish) \$\endgroup\$
    – Kokizzu
    Commented Feb 14, 2019 at 2:45
  • \$\begingroup\$ i updated the last picture @EdMarty \$\endgroup\$
    – Kokizzu
    Commented Feb 14, 2019 at 3:45
  • \$\begingroup\$ Are any of the parent RectTransforms scaled or anything weird? Or do they all have expected values? \$\endgroup\$
    – Ed Marty
    Commented Feb 14, 2019 at 6:38

1 Answer 1

1
\$\begingroup\$

RectTransform does not take any scaling (of itself or any parents) into account when performing layout or determining what the reported rect is. Try doing all UI layout with no scaling, setting only the RectTransform’s anchored position, size delta and anchors for position, and only relying on the CanvasScaler in the root Canvas to set the size on screen that you want.

If that doesn’t solve your problem, try starting from scratch and building just a visual copy without doing any scaling, and find the differences.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .