Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by Thajocoth · May 12, 2016 at 02:50 AM · uicanvaslayoutpanelscreen size

Attach UI elements to screen corners

I have a few UI elements that need to be set to specific screen areas. I've tried a variety of layout objects and content fitters, but none are doing this very simple thing that I'm hoping can be done without adding more code.

I have a button that should always be in the corner of the screen, regardless of screen size. Whatever the lower right screen coordinate happens to be re-sized to, should be this button's lower right screen coordinate. I have another button that goes above that one.

I have similar for the lower left and lower middle, but I'm sure if I can get one working, I can get the others working.

First attempt:

Canvas (Scale with screen size; match width or height; 0.5)

  • Lower Right Panel (Vertical layout group: Lower right, No force expand)

  • Lower Left Panel (Similar)

  • Dynamic Panel (Similar for center; Has a horizontal layout group instead of a vertical one; Buttons are generated in code at runtime and appear centered along the bottom)

Content is childed to those panels.

This works only in one aspect ratio. If I resize the window by a few pixels, the buttons begin to slide off screen sideways & up or down and towards the center.

I've tried the content fitter, and it just moves everything to the screen's center.

I've tried adding a content fitter to the lower right panel. This keeps the buttons in the screen, but they still slide up or left away from the lower right corner when the screen is resized. Settings: Fit in parent; 2.

I've tried doing both in separate panels, one in the other, both having vertical layout groups.

The fact that Aspect Ratio Fitters have an aspect ratio field already told me that it wasn't what I need, since I need aspect ratio to be fluid, not specified. Whatever the window's size is, I need the distance to the corner not to change at all, not even by a pixel. I know I can code this, but I really want to be able to use the UI elements and this is such a simple and standard thing that there must be some easy way to do it that I'm overlooking.

So, what am I overlooking?

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

Answer by corn · May 12, 2016 at 10:56 AM

If all you need is to place two buttons in a corner, then the solution is pretty simple, you only need to set your buttons' anchors right.

The lower right corner is X = 1, Y = 0, so you have to set the anchors like so :

First button (bottom right) : Anchor Min : (1, 0) Anchor Max : (1, 0)

Now your button is anchored to the lower right corner, whatever the aspect ratio of the screen is.

Then to display it right, set the Pivot to (1, 0) : that way the whole button will be displayed on the screen. You can now change its width and height.

For the second button, do the same thing (Anchors and Pivot to (1, 0), set width and height as you like) and put it above the first one by changing its Pos Y (for example, set Pos Y to your first buton's height + 10). That way, your two buttons will always be displayed in the same position.

Check the Manual page for multi-resolution UI for further information.

Comment
Add comment · Show 3 · 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 Thajocoth · May 12, 2016 at 12:27 PM 0
Share

So basically, it's the canvas resizer that's messing me up, and I need to take everything out of the canvas, then anchor everything properly. I will try this today, thanks.

avatar image Thajocoth · May 12, 2016 at 02:24 PM 0
Share

This does technically fix the problem that I've stated. I've even been able to continue to use the panels with the layout groups to keep them automatically arranged by giving these settings and a content size fitter to the panel.

They're completely invisible now, so I've got that to debug... But I can see they're in the right spot. Thanks for your help!

avatar image Thajocoth · May 12, 2016 at 03:03 PM 0
Share

I fixed my invisibility problem by putting them back in the canvas, but adding a layout element with "ignore layout" checked, so it ignores what the canvas changes & acts like it's outside the canvas, but is in the canvas, so it draws on the screen.

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

75 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

Related Questions

5.3.3 Get Position and Size of a Panel 1 Answer

[SOLVED] Image is not visible in Panel (in game view) 0 Answers

Canvas Horizontal aligning two buttons, one bottom left and one bottom right 0 Answers

Canvas Structure for Different UI Panels 0 Answers

Scale all things inside UI canvas 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