Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Positions of UI Elements under Vertical Layout Group

Discussion in 'UGUI & TextMesh Pro' started by RakshithAnand, Sep 5, 2014.

  1. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    56
    Ok,
    I have a canvas in world space. And i have a ui element with Vertical layout group on it.
    now there are 5 Buttons under the vertical layout.

    Now if i access their position using RectTransform.position, all buttons have same position values which is lower left corner of the vertical layout group! Is this a bug or am i doing something wrong?

    Please help, Thank you!
     
  2. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    56
    Well i guess this is a bug,I was reading the position in the Start() method and when i checked it in Update() method, the position returned is correct!
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    The elements haven't been laid out until the layout manager runs. This is at the end of a frame.
     
  4. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    56
    Oh, i did not know about that. Thank you!
     
  5. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    do from the error, it was designed(((
    in some version of Unity is working correctly!!! a bug that decided to leave as it is, and to assert that it should be
    it is not the only case
     
  6. dmoret

    dmoret

    Joined:
    Aug 23, 2017
    Posts:
    13
    Is there a way to find out if it has been laid out yet? I'm having the same problem and I don't really like the idea of just waiting one frame.
     
    xavierarpa and Skyblade like this.
  7. Jai3d

    Jai3d

    Joined:
    Jan 16, 2015
    Posts:
    1
    This will be called twice, but worked for me.

    private void OnCanvasGroupChanged()
    {
    // check transform values
    }
     
    Last edited: Mar 5, 2021