Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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
0
Question by PsychoDuckArcade · Oct 24, 2015 at 10:10 PM · uiresolutionaspect ratio

Maintain aspect ratio of UI element and all it's children and fit screen using black bars if necessary.

So I have a canvas with a black 10:16 image on it. The canvas scaler's UI Scale Mode is set to Scale With Screen Size. I added an Aspect Ratio Fitter component to the image and it works fine, scaling with the resolution and maintaining aspect ratio (not stretching) to always fit in any resolution (using black bars on the sides or top and bottom if necessary). It never cuts off the edge of the screen.

When I child UI elements to the image (which never changes its aspect ratio), the elements act inconsistently. They'll stay properly proportioned to their parent image if it's limited horizontally (black bars on top and bottom), but when it's limited vertically (black bars on the left and right) the proportions get all messed up and change relative to the parent causing them to overlap and go off the image and off screen.

I tried changing the Canvas Scaler's Match to 0.5 but it made no difference. All it did was change the elements' initial sizes which still weren't kept consistent after being limited vertically by the screen aspect ratio.

I tried adding Aspect Ratio Fitter to all the children elements as well, and it DOES scale properly with the screen size, but it forces the rect transform to stretch to fill the parent transform with no option to change it.

EDIT: The UI elements' rect transform settings don't show any change, despite them scaling with the viewport's height while height-limited.

Here it's being limited horizontally and properly scaling to fit and maintaining ratio and proportions of everything: alt text

And here it's being limited vertically. Notice the black image scales and maintains ratio properly, but the child elements do not. alt text

incorrect.png (159.7 kB)
correct.png (152.8 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Onithec4t · Nov 25, 2015 at 11:59 PM

Set canvas render mode to world space.

Comment
Add comment · 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
1

Answer by Xerox_U · May 06 at 07:08 AM

Setting 'Screen Match Mode - Expand' in Canvas Scaler component helped me to get really good results: it doesn't warp any of the children

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 dolphincup · May 24 at 06:00 PM 0
Share

I needed this :D 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

41 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

Related Questions

Preserving aspect ratio for layout group elements 3 Answers

Fixed aspect ratio/resolution independence 1 Answer

Help with Resolution / Scaling 0 Answers

Canvas Scaler settings 0 Answers

Target android/ios with same assets? 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