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
1
Question by nTu4Ka · Dec 17, 2015 at 04:11 PM · uihierarchyordering

Can I implement Sorting Layers behavior in new UI?

Hi,

I have an inventory and it has two major groups in UI: Weapons and Potions. They both have multiple child objects.
In hierarchy weapons stay below potions. It means that its children will always appear above potions children.
I'm implementing drag&drop. So when I drag a potion - i'm setting it as last sibling and it will appear above all other potions. But when I hover over weapons - it will render under them because weapons parent is below in hierarchy.

Is there a way to directly tell dragged potion to render above all other UI elements or I need to fiddle with parents - change they order in hierarchy every time an item is dragged?

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

Answer by TonicMind · Dec 17, 2015 at 05:05 PM

You should keep a reference to the layer of the hierarch that you want a potion (or weapon) to be. This may require some minor but manageable changes to your hierarchy.

So: 1. In your hierarch make sure you have two empty gameobjects for the layers. It should look like this:

Hierarchy Example 1. In your script either create a public variable to assign the layer to from the unity editor inspector, or find the layered object like so: PotionLayerReference = GameObject.Find("PotionLayer"); 2. When you want to place your weapon or potion object on the specific layer, simply attach the desired object to that referenced layer. That should put it on the just below the layer object.

Like so: HealthPotionTwo.transform.setParent(PotionLayerReference);


inventoryexample.png (4.2 kB)
Comment
Add comment · Show 2 · 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 nTu4Ka · Dec 18, 2015 at 04:43 PM 0
Share

That is pretty nice workaround. :) Thanks for sharing it.

avatar image TonicMind nTu4Ka · Jan 11, 2016 at 02:43 PM 0
Share

No problem! :)

avatar image
0

Answer by nTu4Ka · Jan 11, 2016 at 01:48 PM

This is so stupid. I managed to solve problem with weapons and potions but now have to solve problem with other UI elements since:
-if I put inventory at the bottom of hierarchy - its elements will overlap other UI elements
-if I put higher - items won't appear correctly when dragging

Now I feel that I need to write some kind of hierarchy manager just to make UI appear correctly.

Comment
Add comment · Show 4 · 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 Bonfire-Boy · Jan 11, 2016 at 02:50 PM 0
Share

You could create a top layer to put the items in temporarily while being dragged.

avatar image nTu4Ka Bonfire-Boy · Jan 14, 2016 at 01:40 PM 0
Share

This actually is a good in it's simplicity solution. But I would have to set up a manager of some sort to have one instrument that manipulates hierarchy in order not to mess up the tree because after drag is over you need to place manipulated parent where he was. In other case ordering would be slightly messed up and can affect other part of game.

avatar image TonicMind · Jan 12, 2016 at 02:18 PM 1
Share

After a little research (google :P) I found a solution for you!

There's an option within each canvas called Sorting, you can define new sorting layers with it. All you need to do is create a new Canvas for each object you want to be rendered in whatever order you wish. You'll set the layer in the Canvas component within the Inspector Canvas panel. I'd post a picture but my Uni's internet sucks right now, won't let me upload anything, oddly. I'm connected via ethernet, normally its the Wifi, though I've known it to go down.

So basically, just create Canvas Objects with the same render mode (ScreenSpace Layout or something, whichever is default for your game) and set their Sorting layers. You should attach them all beneath one primary canvas. $$anonymous$$ake sure you check the transform values too, something odd happened with the scaling and size when I put together my example.

avatar image nTu4Ka TonicMind · Jan 14, 2016 at 01:41 PM 0
Share

Wow. This is interesting. And looks like requires less coding then creating a hierarchy manager.

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

39 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

Related Questions

Images blocking buttons? 2 Answers

Children of prefab disappear in Hierarchy when prefab parent is clicked,Children of prefab disappear in Hierarchy when prefab is clicked 2 Answers

how to set a public GameObject when button clicked 2 Answers

How to trigger specific button at specific condition when player press back button Android 1 Answer

"UI Toolkit" doesn't appear in Hierarchy 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