Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by darkhog · Jan 25, 2015 at 08:24 PM · uirecttransformheightfailure

[4.6 GUI] Resizing panel to fit it content

So my menu is almost done. It is made to dynamically create list of items from a specific array and uses VerticalLayoutGroup to make it fit together. So far, so good. But there is one small issue, I don't know how to resize panel those buttons used for menu reside in to fit it content which results in menus scrollable too far away in case of short menus or menus that have too short scrollable area to see all items (long menus).

If I use RectTransform.rect.height to try to set height, it says it's read only.

If I try to use sizeDelta, it kinda works, but there is still an unwanted buffer (scrolling past the menu).

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

2 Replies

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

Answer by PorkMuncher · Jan 25, 2015 at 08:28 PM

Try "Content Size Fitter" component!

Comment
Add comment · Show 1 · 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 darkhog · Jan 25, 2015 at 09:21 PM 0
Share

Thank you so much! Need to get used to this, I'm too used to old GUI and so I was trying to do most of it in code.

avatar image
10

Answer by anisabboud · Jul 15, 2015 at 04:59 PM

  1. Add "Content Size Fitter" component to the panel, and set "Vertical Fit" to "Preferred Size".

  2. Add "Vertical Layout Group" component to the panel, and set the padding+spacing+alignment as you please.

  3. For each child, add a "Layout Element" component, and set the "Preferred Height" as you please.

Comment
Add comment · Show 2 · 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 speedacidrain · Mar 01, 2016 at 06:38 PM 0
Share

Thanks!!!!

avatar image ZupaleX · Apr 27, 2016 at 02:14 AM 0
Share

Thats just great

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

22 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

Related Questions

My canvas recttransform.rect.height don't change properly 1 Answer

[4.6 gui] Getting dimensions of 2D UI object (button for example) 2 Answers

Scaling image width in script error 0 Answers

How to set RectTransform size relative to the size of the textbox? 1 Answer

How to find width and height of game object, Unity2D 2 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