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 /
avatar image
3
Question by Ferofax · Aug 07, 2016 at 01:24 PM · uirenderingordering

Making UI elements appear in front of other elements

Hello, I've been working on an inventory system for a little while now. In the past, when dragging an object from one slot to another, I set the item's number in the child list so that it would appear in front of the other children (other UI item objects and slot objects).

However, as I've been working on saving and loading within the inventory system, I've paid for this shortcut; It's been causing a number of problems when I save the object list contained within an inventory and later when reinstantiating (loading) a specific inventory.

Long story short, I'm trying to find a way to make a UI object appear infront of other UI objects without changing its position in the child-parent hierarchy. If anyone has any information on how I might do this, I'd be extremely grateful.

Godspeed & May the Force Be With You

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

Answer by Yujingping · Aug 08, 2016 at 04:00 PM

Hi there is one solution I could provide on your situation. As we all know UGUI renders all the UI objects based on their hierarchy in the project. The more superior an object is in the hierarchy, the earlier it is rendered, and thus it is displayed "deeper" on the screen. So the problem is how to change the hierarchy of the objects, both during the editing and running. In editing mode you may just change the priority of the siblings in the hierarchy -- drag and drop, that is easy. If you want to change the relationship during running time, you definitely need to script and you may take this official document for reference: Official Scripting API So now lets make some examples. How to make a text rendered in front of all the siblings, its parent and all the other objects placed above the parent in the hierarchy:

 text.transform.SetAsLastSibling (); //Since it is rendered the latest, it is displayed on the top.

How to make a sprite rendered behind any other UI objects of its siblings:

 sprite.transform.SetAsFirstSibling ();

Suppose that you have 8 siblings under a parent, and you know that a text is the last sibling, a sprite is the 6th sibling. How to make a sprite rendered between the text and the sprite:

 anotherSprite.transform.SetSiblingIndex (7);

Unluckily you don't know the sprite's sibling order, how to get it:

 int spriteOrder = sprite.transform.GetSiblingIndex ();

Up to now we have successfully resolved the problem of adjusting render order of UI objects when these objects are UNDER THE SAME PARENT. What if they are under different parents? For example an object SonA is the 7th child of A, SonB is the 8th child of B, and you want SonA to be displayed as exactly the 5th one in B. Honestly speaking, if such a situation does happen STATICALLY, it is definitely due to inappropriate designing and the obvious way is of-course re-designing the whole hierarchy. However if the situation is that you are trying to drag something out of the box, or display a pop-up-menu, you may temporarily change the hierarchy by script during runtime and restore it after the operation. (This is exactly what NGUI does in its older versions. Currently only the drag and drop in NGUI causes a temporary hierarchy change. ) Feel free to ask more. GL & HF!

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 Ferofax · Aug 10, 2016 at 01:03 AM 0
Share

Wow that was terrifically helpful. Thank you so much for taking the time to explain this concept in such detail.

avatar image Rukas90 Ferofax · Dec 04, 2017 at 04:56 PM 0
Share

Hello.

I heard that Get and Set Sibling Index only works inside the editor. Is that true?

avatar image FMaz · Mar 18, 2018 at 01:59 AM 0
Share

Last paragraph helped me understand why the child kept going under his parent's sibling... What a mess to fix tho... Wish we could simply define Z index...

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use two cameras in VR to display 3D object on top of UI panel? 0 Answers

Have trouble with UI arrangement. 2 Answers

Use custom render pass to render world space UI without post processing 0 Answers

Problem with Fonts rendering 1 Answer

Does Unity 5.6 free/pro provide support to open external applications inside the Unity scene? 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