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 /
avatar image
0
Question by Longman1981 · Feb 20, 2019 at 12:39 PM · uiaspect-ratioresolutions

How do you prevent in game UI from overlapping main game objects

Take for example Unity's document about UI scaling: UI for multi resolution

now if this buttons are available while playing game, how do I prevent this buttons from overlapping on main character for example? I know I can anchor it to the corner and scale it, but can I somehow ensure that it won't overlap my main character, no matter resolution/aspect ratio?

Comment
Add comment · Show 7
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 xxmariofer · Feb 20, 2019 at 02:26 PM 0
Share

do you want the button to scale so it is not touching the object? or just to be renderer behind?

avatar image Longman1981 xxmariofer · Feb 21, 2019 at 09:30 AM 0
Share

I want want to ensure it doesn't touch object, but stays visible. Like for example if I'm making tetris clone, I have grid in world space, and I have UI buttons on canvas, one UI button is placed on the left of the grid. Now if I test it at 1080/1940 it looks fine, ui buttons doesn't overlap on my grid, let's say I can also anchor it to the screens left side for example and add canvas scaler, now UI buttons will scale based on pixels and game view will scale width to match with current aspect ratio, now if screen is narrow, button will get closer to grid, and if screen is extremely narrow than button will overlap my grid, so how do I make sure that doesn't happen? Generally there seems to be no colleration between UI and world space, almost all games have UI in there game but if you can't define how UI related to world space game objects I'm not sure how anyone makes sure that everything works fine.

avatar image xxmariofer Longman1981 · Feb 21, 2019 at 09:39 AM 0
Share

i think the easiest solution for you is to set your canvas in world space too, and remove the canvas scaler component. so that the canvbas always stays the same world space position as your elements. you can later repositionate the camera or change the ortographic size of the camera for the camera (for example) always have the same witdh in all resolutions. take into account your camera height will be twice your camera.ortographic size, so if you want to always stay the same height in all resolutions is a simple calculation.

Show more comments
avatar image bpaynom · Feb 20, 2019 at 02:57 PM 0
Share

Is your game 2d or 3d? Your canvas is worldspace, cameraspace or overlay?


One thing you could do is to use a collider and OnTriggerStay () or OnTriggerStay2D(), move the button or scale it down.

avatar image Longman1981 bpaynom · Feb 21, 2019 at 09:31 AM 0
Share

it's 2d. Canvas is in it's default state, that's cameraspace I believe.

0 Replies

· Add your reply
  • Sort: 

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

168 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 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 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

Canvas aspect ratio 1 Answer

Inconsistent Sprite location on screen 1 Answer

Unity crashes when using ExecuteAlways on a UIBehaviour 0 Answers

How to see what the UI canvas will look like in the final build? 0 Answers

Pixel Perfect and Forced Aspect ratio 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