• 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
Question by RealMTG · Dec 07, 2014 at 05:22 PM · uiexpand

Content size fitter and scroll rect

Hi!

I have this area that loads levels and for each level there is a button. I need the scroll area to expand for each button. I asked that question before and they said I should apply a content size fitter to the content and it seems to work at first glance. But then when there is more levels then the content can fit nothing happens. The scrollbar doesn't expand and the content doesn't expand. What should I do? I have both the horizontal and vertical fit on Preferred Size. How I do I get it to expand for each button?

Thanks in advance!

Comment

People who like this

0 Show 2
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 RealMTG · Dec 08, 2014 at 05:30 PM 0
Share

Do anyone know how I would do this?

avatar image RealMTG · Dec 09, 2014 at 05:59 PM 0
Share

I'm sorry for being impatient but I really need help with this!

1 Reply

  • Sort: 
avatar image

Answer by Mmmpies · Dec 09, 2014 at 06:37 PM

Hi RealMTG,

I put an update on the original post when I saw this. You're right my solution did look like it'd work but when you try to scroll it doesn't I hadn't noticed as I just dragged the content page which did move and snap back.

I'm currently trying to get mine to work, it's almost there but not quite. For me the following line:

 scrollArea.offsetMax = new Vector2(scrollArea.offsetMax.x, (MenuItemCount * 223));

Works, as I create each item it dynamically increases the size of the scroll panel by increasing the MenuItemCount by 1

MenuItemCount = MenuItemCount + 1;

223 is just the height of my prefab with a tiny bit of padding. Just need to refine it a bit for me.

Should add scrollArea is the scroll panel that's the parent of the instantiated objects. I only have 1 column but if you have more than 1 then you'll need to calculate the first part of the Vector2 as well instead of just getting it's current value with "scrollArea.offsetMax.x".

Hope some of that makes sense.

EDIT:

Oh and the way I'm calling my menu items is really complex, it's a list but with filters on it so difficult to get a count on the number of items I'm creating, if say you want to return everything in a list just get the .Count and set the offsetMax.y = myList.Count * prefab height to that.

EDIT 2:

And another thing I had trouble with, set the anchors of the panel that you want to scroll to the corners but the parent with the "Scroll Rect (Script)" Component on it leave the anchors in the middle.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

26 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

Related Questions

Expandable List using UI 1 Answer

Fitting UI element height to content while expanding width to fill screen? 2 Answers

Scroll view not resizing properly with dynamic content 0 Answers

Find out default inspector height 1 Answer

Text Preferred Height not expanding even with content size fitter 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