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
0
Question by Wuzseen · Jan 15, 2015 at 05:14 AM · canvasscalelayout

Scaling Canvas and Layout Group

I have a canvas set to scale according to a reference resolution.

However it seems my layout groups don't actually scale.

These two screenshots illustrate the issue.

Intended Look at "Normal" Resolution: http://i.imgur.com/wQZB6wh.png

Look at a Smaller Resolution: http://i.imgur.com/KGZ1eFI.jpg

In the smaller resolution I photo I just increase the size of the game window afterwards to make it a bit clearer.

I'm not really sure what I should be doing--if this is even a layout group issue.

Each of the rows in this UI are spawned at run time. They're a prefab with a layout element that sets a minimum height of about ~58 units. These are children of a vertical layout group with a content size fitter. This layout group component scales to its container but the elements inside don't seem to be scaling properly.

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
0
Best Answer

Answer by NirielNabokov · Jan 15, 2015 at 02:39 PM

I feel slightly confused by the description of your setup, so forgive me if I am misunderstanding.

From my point of view, you wish to achieve a result but you are using the tools that are meant to do the exact opposite.

1) Setting a minimum height in the LayoutElement of a row will prevent that row from shrinking vertically. Therefore, it will not get smaller when the window is getting smaller.

2) ContentSizeFitter is meant to force the parent to obey the wishes of the children. Buttons say "We want to be that big", and parent says "ok then, I will expand until you all fit". What you want is the exact opposite: the children have to obey the parent and shrink/expand to the size that the parent gives them.

Therefore, if you want the children to obey the parent, you should not be using ContentSizeFitters or LayoutElements.

BUT: even if your button shrinks when the parent orders it, the font size of the text will not. Size 16 is size 16, and if the text is given less space then it will start to wrap and overflow/disappear. Likewise, the padding of the elements will remain constant: the row is 500 pixels-wide with 10 pixels of padding, or it is 100 pixels wide with 10 pixels of padding.

So what you want may be, instead, to use the Canvas Scaler component. Design your UI for a specific resolution with the scale of the canvas set to 1. During the game, detect the resolution and change the canvas scale accordingly. Then you can use all the ContentFitters and LayoutElement that you want, they will help making sure that the window looks good at the ideal resolution.

Comment
Add comment · Show 7 · 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 Wuzseen · Jan 15, 2015 at 04:01 PM 0
Share

I may fiddle with this sort of solution.

The content size fitter & layout element is the way to make a dynamic scroll view. The content size fitter doesn't constrain horizontal width and adjusts itself to the size of the children. The $$anonymous$$imum height of the button rows then are effectively their actual height.

Otherwise you understood it pretty much right!

avatar image NirielNabokov · Jan 15, 2015 at 04:28 PM 0
Share

Oh I get it. Then we should expect that the content of the rows does not fit horizontally. However, it should still fit vertically and obviously it does not happen. What LayoutGroup/LayoutElement/Fitter did you put on your scrollrect?

avatar image Wuzseen · Jan 15, 2015 at 04:29 PM 0
Share

A vertical layout group on the content of the scroll rect. Content size fitter unconstrained horizontally but constrained to preferred size vertically. Each element that gets added to the scroll view has a layout element with $$anonymous$$imum height set to about ~58 or thereabouts.

It's effectively a "grid" but the grid layout sets an exact pixel size on each element so I swapped to using the vertical layout group as it shoudl expand horizontally and resize the children accordingly.

avatar image NirielNabokov · Jan 15, 2015 at 04:33 PM 0
Share

So something must drive the width of the content of the ScrollRect. I imagine that the ScrollRect does it? What is on the ScrollRect itself? (not on its content)

avatar image Wuzseen · Jan 16, 2015 at 12:59 AM 0
Share

The scrollrect component and a mask + image.

Show more comments

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

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

Layout error after crash has effected canvas scaling 1 Answer

UI scaling issues 2 Answers

Canvas will not fit to screen upon build 1 Answer

Layout Groups Do Not Take Scale Into Account 1 Answer

Scaling a menu bar 1 Answer


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