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 bksbunnyhead · May 14, 2017 at 10:46 PM · unity 5uiscenes

How can I make sure an UI element is rendered on top of the others if my game has multi scene hierarchy?

In my game hierarchy, there are multiple scenes configured roughly like this

   Scene 1
        Canvas
              Image 1
              Panel A
                    Image 2
                    Image 3
                    Image 4
              Panel B
              GridLayout A
    Scene 2
         Canvas
                Image 5
                Image 6
                Panel C
                      Image 7
                Grid Layout B
                Panel D

I understand the UI rendering order in single scene setup, but not in multi scene setup like this. Currently what I want to achieve is Panel D in Scene 2 to be rendered on top over any other UI elements, including UI elements in Scene 1. When the game is running, Panel D in already rendered on top over other UI elements in Scene 2, but I don't know how to make Panel D is rendered on top over other UI elements in Scene 1. Sometimes it's rendered behind GridLayout A, or Image 4, or Panel B, ...

Is there any simple way to make this possible? Or is it not supported / limited by Unity because of this statement?

Cross-Scene references are not supported, and are prevented in Edit mode. In Play mode they are allowed, because Scenes cannot be saved.

My game doesn't have any sprites game object, all sprites are only being used in UI Image game object. All I have in my game is either empty game object or UI game object. All canvas render mode is set to Screen Space - Overlay. I've tried changing order of the scenes, changing order of the hierarchy, changing order of scene build index, googling around (but majority the question is about multi camera/ single scene setup; what I got is multi scene setup with single camera, I don't think I found any closely related to this), but what I got is more confusion. Please help, I will greatly appreciate it.

Extra note: I created this multi scene setup in order to achieve kind of "swappability" feature in my game. Please, don't advice me to flatten the multi scene setup.

Comment
Add comment · Show 2
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 RobAnthem · May 14, 2017 at 11:47 PM 1
Share

You could move it in the hierarchy at runtime using SetSiblingIndex like this.

 public class Top$$anonymous$$over : $$anonymous$$onoBehaviour
 {
     public GameObject AlwaysOnTop;
     void OnEnable()
     {
         AlwaysOnTop.transform.SetSiblingIndex(transform.childCount - 1);
     }
 }

Just an idea.

avatar image bksbunnyhead RobAnthem · May 15, 2017 at 09:47 AM 0
Share

@RobAnthem Thanks for your help, but I've tried it and unfortunately it doesn't work. It still has the same effect if I manually set Panel D as the last UI gameObject in Editor. Panel D is still displayed behind some UI gameobjects from scene 1. I think I'm starting to regret using multi scene setup for my current project...

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by HarshadK · May 15, 2017 at 10:26 AM

The hierarchy based draw order works for UI elements within the current scene only so setting a UI element as last child in a Canvas will render it over all UI elements from that canvas. Similarly you can draw elements from one canvas over another by setting the hierarchy order of canvases. But it works within same scene too.

To get the desired effect of having one element drawn over all other elements from other scene you can set the Sorting Order of the canvas. This will allow you to render a canvas over other canvases (even from other loaded scenes). So in your case setting the Sort Order of your canvas from scene 1 to 0 and Sort order of canvas from scene 2 to 1 will draw the canvas from scene 2 over the canvas from scene 1. Then you can set your Panel D to be last sibling in canvas from scene 2 to render it as the top most.

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 unity_m0tSgrBykM-Eow · Apr 06 at 05:34 AM 0
Share

Simplified:

Add Canvas component to your objects and set same Additional Shader Chanels to be same as ur parent canvas. Then check Override sorting and use Sort order as your sorting value.

Note that if you want to use UI raycasts (buttons etc.), also add Graphics Raycaster component.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Drage 3D object from Scene to UI? 0 Answers

Failed to convert sprite texture type in unity UI 0 Answers

When loading into a new scene my UI doesn't work anymore? 3 Answers

UI in Scene View only Rendered Backward 0 Answers

Loading a scene after a random amount of time. 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