Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GridLayoutGroup setting all children to size/positon 0,0,0 in First Frame?

Discussion in 'UGUI & TextMesh Pro' started by The_MrX_, Feb 18, 2021.

  1. The_MrX_

    The_MrX_

    Joined:
    Aug 25, 2019
    Posts:
    12
    Basically I was making a inventory system and while working on the GUI, I noticed that if I added a Layout Element(with ignored Layout Enabled)to the items prefab, the items would be placed in position 0,0,0 with size 0,0 when the game started.

    Upon further inspection, I realized that when my code was setting the items to the itemSlot's anchor positions and size in the Awake Method, all the itemSlot had the position of 0,0 and size of 0,0,0. Even though they were not instantiated via script and already had the correct size/position before the play button was pressed. (note that this behavior didn't happen if the GridLayoutGroup was not present)

    So I fixed it by simply disabling the GirdLayoutGroup in the editor and then enabling it during runtime after the items had been created and positioned.

    But is this a bug or is there some intended reason for the GridLayoutGroup changing the positions/sizes of all items to 0 in the first frame?(from looking at Update logs, its fixed by the 2nd frame)