Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
  • Help Room /
avatar image
10
Question by Spider_newgent · Mar 08, 2017 at 07:14 PM · uicanvasui imagesorting layers

Set different sorting layer for each child of a canvas, (Background and UI)

Hi.

I have a canvas set up with a couple of children: 1. An image for the static background of my scene/level. 2. A panel which houses a drop down menu, (containing a grid of inventory objects).

The background panel should be on the "background" sorting layer and appear behind everything in the scene. Meanwhile the inventory panel should be on the "UI" layerwhich is at the absolute front and always is rendered over everything else.

Although I can set the sorting layer for the whole canvas it doesn't seem possible to set the sorting layer of each element individually.

Is there a way to achieve this, should I use 2 canvases, or is there a third, alternative option?

N.B. I know it's possible to have 2 canvases. My question is about the most elegent solution, not how to hack it together.

Thanks

Dan

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

Answer by ahung89 · Mar 10, 2017 at 02:55 AM

You can actually set the sort order of individual UI elements by adding a Canvas component directly to the element and then checking the "Override Sorting" option. This doesn't require you to re-organize your hierarchy at all. Just make sure to also add a "Graphic Raycaster" component if you want that element to receive click events.

Comment
Add comment · Show 11 · 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 tonialatalo · Aug 21, 2017 at 12:36 PM 1
Share

Thanks, am going with this now - I wonder, does it have downsides?

avatar image Xanatos_88 tonialatalo · Jul 14, 2018 at 06:51 PM 0
Share

Did this solution work for you?

avatar image jamiahuswalton Xanatos_88 · Aug 22, 2018 at 04:20 PM 0
Share

The solution worked for me. Thanks

avatar image Fattie tonialatalo · Feb 09 at 07:18 PM 0
Share

perfect, and no downsides

avatar image Symposium10000 · Jun 04, 2019 at 05:06 PM 0
Share

Just wanted to say thanks this is an easy solution and will save me some frustration in the future!

avatar image naviln · Oct 30, 2019 at 04:21 AM 0
Share

This is great, thanks!

avatar image Bloy- · Dec 02, 2019 at 04:51 AM 0
Share

Thank You!

avatar image tomas-jakstonis · Jan 31, 2021 at 04:33 PM 0
Share

Wow, thanks, you saved me a lot of time!

Show more comments
avatar image
6

Answer by hexagonius · Mar 09, 2017 at 06:52 PM

From what I know, the canvas works different from sprites as it renders its elements according to the hierarchy order, top to bottom. This means, the whole canvas renders in one go. With a single Canvas setup two possible problems arise:
- The canvas will need way too much resources, because it rebuilds all the time
- You're getting a hard time to get the order of elements right (well, ok not so much)

I suggest using 3 canvases, Back, Middle and Front. If background and foreground are static, that means those canvases don't need any recalculation ever and you have it easy setting your game on the middle one. If it's a game :)

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 Calfur · Nov 30, 2020 at 09:12 PM 0
Share

Great explanation, good approach

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

144 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

Related Questions

Block Input.GetMouseButtonDown() when clicking on UI element 2 Answers

Manipulate ui canvas button hitbox 2 Answers

Can i treat multiple image components as a single image? 0 Answers

How to move a UI Image in the z axis? 2D 0 Answers

Non-root Canvases will not be scaled: My UI has disappeared 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