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.

Question RectTransform localPostion.y returns global position???

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

  1. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    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:
    3,394
    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