Script and Gameobject position mismatch?

Hey, I have a problem that position values are different on Debug and Inspector, or on Object and inside Script.

Let me explain with an image:


TestDot 30 has Position X: 327.2 Y: -31.7 in Inspector, but Debug says it has X: 788.3, 276.6.

Therefor, my problem, the lines mismatch. Positions in the script are not like positions in game.

The blue dots are start, middle and end points of the line. The green dot is the control/bend point.
The green line is a manually set UILineRenderer to start, control, end points.
The red dots are points across the calculated line inside the script - and they are perfect.
The white line is an instantiated UILineRenderer inside the script with start, control, end point passed.

Green (manual) Line:

White (generated) Line:

How can I get the proper position vectors for the generated (white) line?

You are looking at a RectTransform. Its position has absolutely nothing to do with world positions if it isn’t a world space UI, which doesn’t seem like it is.

As a rule of thumb: avoid directly reading from or manipulating a RectTransform. In all likelihood it is controlled by a UI layout anyway. Generally speaking, the values of a Transform and that of a RectTransform are not compatible and require some form of translation between them such as converting screen/view space to world space coordinates.

How can I do that?
TransformPoint and InverseTransformPoint gave messy results.

I’d recommend checking out RectTransform.anchoredPosition and RectTransformUtility.