Search Unity

Question RectTransform localPostion.y returns global position???

Discussion in 'UGUI & TextMesh Pro' started by Gordon_G, Aug 20, 2022.

  1. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    In Unity 2021 LTS, why in the world am getting the global position of a UI object when I access its rectTransform.localPostion.y?

    In the inspector I see the local y position of a RectTransform
    upload_2022-8-19_23-8-33.png
    But when I turn on debug mode, y shows the global position, which is the value returned by localPostion.y:
    upload_2022-8-19_23-11-21.png

    What is going on with that?
     

    Attached Files:

  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    Wrong sub forum. This is the sub forum for the new UI toolkit, not the old uGUI.

    In any case, local position != the editor friendly values displayed by the rect transform.

    Local position is a property of Transform, of which RectTransform inherits from. You would want to use probably anchored position or the other rect transform specific values: https://docs.unity3d.com/ScriptReference/RectTransform.html