5

When I`m adding new elements on vertical layout group and when there is no more place to them vertical layout group starting to expand downstairs. How to make them adding from the top of each other?

What do I want:

  • 4th element
  • 3th element
  • 2nd element
  • 1st element

First element is always downstairs, next elements are spawning at top of it.

Thanks.

6 Answers6

1

Ok, I found one solution. Idk if it is correct, but it is the simpliest one. Just need to rotate "Rect tranform" for 180 degrees. Solution in image

The video of the result: google drive.

1
    yourGameObject.transform.SetAsFirstSibling(); is the solution.

Can be done at the end of other transform actions.

    button.transform.parent = ServerMessagesContent.transform;
    button.transform.position = ServerMessagesContent.transform.position;

    button.transform.SetAsFirstSibling();
Shantu
  • 145
  • 11
1

In the Vertical layout group(component) you can change the Child Alignment to Lower Center.

Rotating the whole UI element is not a good idea(might cause major headache down the line) and since this thread is the first thing that came up while googling, I felt I should drop this here for future devs.

Martin
  • 19
  • 3
  • 1
    Child Alignment to Upper Center still makes the list expand downwards instead of upwards. – idbrii Jun 05 '19 at 19:16
  • At the time i made this I wrote the wrong direction :P fixed to lower Center but the child alignment still controls the direction of expansion. I also want to ad this link for which even has a screen shot https://stackoverflow.com/questions/55279138/how-change-expanding-direction-of-verticallayoutgroup-in-unity-without-rotating. – Martin Jun 20 '19 at 17:27
  • The child alignment does NOT control the direction of expansion, that controls your position in the parent rect – Sniffle6 Sep 22 '20 at 23:03
1

The easiest way is - assuming you're using a script to add objects to the parent - is just to assign the child index in the script so that each new entry appears above the last instead on below.

Documentation can be found here: https://docs.unity3d.com/ScriptReference/Transform.SetSiblingIndex.html

Cal
  • 11
  • 1
0

Rotation is the worst possible thing which I can do to make my things spawn from bottom to top and child alignment will not help you either instead make a list, put all the things which need to be spawned and reverse the list and spawn . It worked for me

0

This is the way I found to do this and it worked for me on Unity 2020.

On the parent element with the vertical layout group set the child alignment to upper center and set the pivot under rect transform to 0.5 1. Which locks it in place and spawns the latest item in descending order.