How to change direction of expanding vertical layout group unity3d?
Asked Answered
E

7

6

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.

Eyla answered 3/4, 2017 at 14:56 Comment(2)
What do you mean by "How to make them adding from the top of each other?"?Rainger
Vertical layout group shall expand topstairs.Eyla
E
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.

Eyla answered 3/4, 2017 at 19:36 Comment(1)
rotation was a good a idea but in with scrollbar it does not focus the last objectCasals
A
2

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.

Adna answered 23/2, 2019 at 16:42 Comment(3)
Child Alignment to Upper Center still makes the list expand downwards instead of upwards.Berkshire
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 #55279638.Adna
The child alignment does NOT control the direction of expansion, that controls your position in the parent rectGobetween
E
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.

Eyla answered 3/4, 2017 at 19:36 Comment(1)
rotation was a good a idea but in with scrollbar it does not focus the last objectCasals
C
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();
Casals answered 31/12, 2017 at 17:49 Comment(0)
C
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

Condensation answered 2/10, 2022 at 6:46 Comment(0)
S
1

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.

Siler answered 23/7, 2023 at 9:2 Comment(0)
O
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

Offhand answered 26/5, 2021 at 5:20 Comment(0)
A
0

I figured it out, without any rotation, set the vertical layout with content size fitter like this

here's the result

Aeroneurosis answered 23/8 at 13:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.