I’m working with panels and layout groups. In the image below, I need the panel containing the images and texts to be vertically centered in the window. I currently have the panel that holds them set to a vertical layout group with 0 spacing and Middle Right child alignment. They should also dynamically change locations if there are more/less items in the vertical layout. For example, if “4th Place” is removed, 2nd and 3rd should automatically move to the center of the layout. Right now, they are stuck in their locations.
See images for vertical layout and its properties.
Hard to speculate without more information. Is the Vertical Layout Group enabled? Is there extra space in it? Do the children move at all when you change the “child alignment” setting? Are the children set to ignore layout?
Pictures showing the inspector view of the layout group and a child, the object hierarchy, and the scene view might (or might not) help.
Also consider creating a new, very simple layout from scratch, see if you can get that to align correctly, and if so then look for differences between that and your current layout.
Sorry this is late… hopefully it gets seen. Yes, the vertical layout group is enabled. Here is an updated image of the layout and the vertical layout properties. All I need is for the items to remain centered if one or more of them is not visible. For example, if “4th Place” is disabled, the other two should move to the center of the layout; at the moment, removing “4th Place” doesn’t change the location of 2nd and 3rd.
What do you mean by “not visible”? Are you disabling or removing children at runtime? You might try using LayoutRebuilder.MarkLayoutForRebuild to force the layout to re-evaluate after you’ve changed things.
I call SetActive(false) at runtime when some of the items aren’t needed. However, this also happens in the editor. I test it by deleting one of the three items on the right while in the editor, and the other two stay in their place instead of moving to the center. I would like anything in the layout to be centered.
Well, that sounds like incorrect behavior. You should consider trying to recreate this in a small sample project and then submitting it as a bug report to Unity.
As a work-around, you might see if enabling and disabling the layout group (or the game object it’s attached to) causes things to move to their correct positions.
I’m guessing you’ve moved on from this issue by now, but for anyone who happens upon this in the future, this is likely the result of the width/height not being set correctly for the gameObject with your layout group attached