• 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 JstizUnity · Jun 29 at 09:24 AM · button trigger eventsbuttonstates

Making an unmovable button

Hello, so I'm new to programming / Unity and am currently making a 2d dungeon crawler. I am trying to make a button to "Speak to Old Man" and have it not move with my game (I.E make the button always appear directly under the Old Man), but have been having difficulties. I originally tried having the button and dialogue box share a canvas, but couldn't figure out how to make the button stay directly underneath the old man. I then tried creating a second canvas with render mode World Space and placing the button in there but it then becomes invisible no matter the sorting layer I set it to.

Current example with 1 canvas: link: [1]: https://gyazo.com/694011d0b2076730d492ebaf9d6fe96d

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

Answer by Fressbrett · Jun 29 at 06:23 PM

You actually do want to use a worldspace canvas for that, they are built exactly for the kind of situations you are dealing with, a moving camera while the canvas should stay on a fixed worldposition. Using an overlay canvas or a screen space canvas will keep the canvas on the same position on the screen, but with a moving camera that is not what you want here.

Your problem seems to be that your canvas is invisible when set to worldspace. There are multiple ways to fix this:

  • First of all, imagine your worldspace canvas like an actual object within your scene, which thus can also be obstructed by anything infront of it. So check that the z position of your canvas is closer to the camera than the z position of all other objects on your screen.

  • Depending on your Render Pipeline you can also create "global sorting rules" for rendering. Within the URP (Universal Render Pipeline) for instance you can create "Render Features" within your ForwardRenderer asset, in which you could define that all objects on the layer "UI" should always render AFTER all other opaque objects have rendered (or after post processing... whatever you want). Using this approach it doesn't matter anymore what Z position your canvas has, it will be always rendered infront of all other stuff.

Comment
Add comment · Show 5 · 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 JstizUnity · Jun 29 at 08:13 PM 0
Share

Thank you for the response, do you think I should I accomplish this by making a second canvas with only the button on it? Or editing my existing canvas (that contains my dialogue box, etc.) and making that into worldspace?

avatar image Fressbrett JstizUnity · Jun 30 at 10:46 AM 1
Share

Everything that should move with the camera, for instance a health bar, can be kept in a single (overlay or screenspace) canvas, since the position of those will be "fixed" relative to the camera.

Everything you want to display within the world needs to be in a worldspace canvas. You don't want EVERYTHING within your world on a single worldspace canvas. Instead, try to group things cleverly:

You talked about the button underneath the old man, which is an object within your world. Say that old man moves, then everything UI related that should move with that old man can be in a single worldspace canvas that is child of that old man object.

Similarly, the "+5 Coins" that appear when you open that chest could be displayed on its own canvas child of that Chest.

It's good practice to separate things into multiple canvases, since when one element changes (for instance when your coin message appears once you open the chest), then the whole canvas needs to be redrawn, even other text that might not have changed (the old man button in this case). That is pretty resource intensive, thus you want to separate those into different canvases. Read this guide for more on best practices when it comes to canvases.

avatar image JstizUnity Fressbrett · Jun 30 at 10:09 PM 0
Share

Thanks a lot man, makes so much more sense now! One final question I do have. When reading other guides and such I've mentioned others say this similar thing of making an object a child of another object. What exactly does this mean? Or if you know of a nice video explaining it that would be very cool. Thanks again.

Show more comments
avatar image
0

Answer by vish_faldu · Jun 29 at 09:54 AM

You can look into the concept of Overlay Camera.

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 Fressbrett · Jun 29 at 06:15 PM 0
Share

I believe he wants to achieve the opposite, he wants the button stay "under the old man" which is a worldspace postion. Thus world space canvas should be the way to go.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

139 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

Related Questions

how to insert hover effect on unity button and active color button when the button is being click ? 0 Answers

Highlighted buttons stay highlighted when I deactivate a canvas. No way to unhighlight them. 1 Answer

UI button mobile - want a button drag to register as a click 0 Answers

I want to change the fire button when I change the weapon. 0 Answers

How to create simple stage systems? 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