Search Unity

Bug Horizontal layout not initializing

Discussion in 'UGUI & TextMesh Pro' started by Fatamos, May 3, 2022.

  1. Fatamos

    Fatamos

    Joined:
    May 27, 2020
    Posts:
    12
    So I have this generated timeline where I instantiate game objects. They're generated in horizontal layout group but they get in order only when I alt+tab unity window, or if I try to move one item manually (then the rest of the items glitch out a little bit but they get in order eventually). I've done some research and tried Canvas.ForceUpdateCanvases and also tried things from this thread. None of this helped. Is this a known Unity bug or am I doing something stupidly wrong? I tried generating items using coroutines and tried to move the whole container with DOTween DoMoveX but that also didn't work. Any ideas on how I could fix this problem? Thanks :)
     
  2. Fatamos

    Fatamos

    Joined:
    May 27, 2020
    Posts:
    12
    So I fixed the problem by changing the value of horizontal layout group like this:
    Code (CSharp):
    1.             yield return new WaitForEndOfFrame();
    2.             _yearSectorContainerTR.GetComponent<HorizontalLayoutGroup>().spacing = 251f;
    3.             yield return new WaitForEndOfFrame();
    4.             _yearSectorContainerTR.GetComponent<HorizontalLayoutGroup>().spacing = 250f;
    But I believe this is not the only solution to this problem...
     
    unity_w-y-iaZSpOFV6g likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    You're discussing UI, this is the 2D forum.

    The UI forum is here.

    I'll move your post.