Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by benjaminvancaspel · Jan 16, 2018 at 04:59 AM · 2duilayoutverticalhorizontal

How to lock element width or height in a vertical or horizontal layout?

I want to achieve the following for a group of buttons within a horizontal layout group but have been completely confused by the documentation that is provided:

alt text

I want to be able to lock one item, lock one element or limit the max width of an item whilst the others are flexible or free to resize their width. I believe that this would work the same with all of the layout scripts, Horizontal Layout, Vertical Layout and Grid Layout

buttonlayout.png (8.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
34
Best Answer

Answer by benjaminvancaspel · Jan 16, 2018 at 05:14 AM

Rather unintuitively this is how it actually works.

You need to first make sure that your GameObject with the Horizontal Layout Group applied has Child Controls Size checked for "Width" and "Height". You then need to have Child Force Expand "Width" = unchecked, "Height" = checked.

Locked Item: Needs a Layout Element script added to it.
- Preferred width: set to the value you want.
- Flexible Width: 0 (if it's left at 1, it'll just be flexible with 100 added to it and yes you have to check a box for "flexible" when you want it to not be flexible)

Flexible Item: Needs a Layout Element script added to it.
- Flexible Width: 1

If you leave the Flexible Width off, it will just collapse the button's width.

The results are consistent once you get the hang of it, but the problem is bending your head to click on all the different settings with names that don't fit to get the right numbers.

Be careful if you're going to use this for a Vertical group to set Child Force Expand "Width=checked" and "Height=unchecked" on the layout group

alt text


layoutlocked.png (59.4 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Massan · Nov 22, 2019 at 08:46 PM 0
Share

Life Saver! Thanks!

avatar image vonSchlank · Oct 14, 2020 at 01:49 PM 0
Share

Eternal life and forever free beer for you, my friend!

avatar image Splendidus · Oct 28, 2020 at 10:46 AM 0
Share

Why isn't this in the official tutorial? Great explanation, thank you!

avatar image Develax · Jun 28, 2021 at 02:37 PM 0
Share

When using Flexible Width: N you also have to set Preferred width: 0, otherwise it could be taken from the content (from image, for example).

avatar image Jayme65 · May 29 at 12:40 PM 0
Share

Not only responding but taking the time to make this very telling illustration...it's fantastic, thank you!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

191 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Vertically Stationary Camera for 2D? 0 Answers

Make movement vertically,How to move Vertically? 1 Answer

How to change the height of a button according to the height of the text in it? 2 Answers

How can I make Horizontal Layout Group starts from right to left? 4 Answers

How to control "Horizontal" and "Vertical" axis using UI Buttons 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges