Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 syclamoth · Oct 09, 2011 at 11:33 AM · c#guiguilayout

GUI Depth Sorting

I am trying to create a menu structure which exclusively uses GUILayout so that it automatically sets itself out on any screen resolution. So far so good. Part of this system is a generic 'Drop-Down List' method, which uses the GUIUtility to reserve an slot for its base, and then when it is clicked draws a menu with all the elements in a generic list around the one currently selected- like

                      item1
 line of normal text- item2
                      item3
                      item4

Then when you click on one of them, it disappears the list and returns the element of the list that you indicated. All well and good.

The problem is that when I have several of these lists on top of one-another, when I open one list, instead of clicking the buttons in the list, it tries to open up the other lists (or in fact, any clickable GUI element) which are below it! I'm using GUI.depth to make sure the list always draws on top, but it doesn't seem to help with the clickable stuff. Does anyone have a neat solution to this? I know exactly where the rectangles are on the screen (I use them along with the mouse position to automatically close the lists if the user mouses away from them), but I can't think of a way to stop it from clicking my other buttons!

Comment
Add comment · Show 5
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 fherbst · Nov 16, 2011 at 09:22 AM 0
Share

Could you check wether they are clicked in the correct order? (Debug a click number or something). If yes, you could simply block the others from getting the click after the first click went to the correct control.

avatar image syclamoth · Nov 16, 2011 at 09:25 AM 0
Share

They don't get clicked in the right order, no. They get clicked in the order they are drawn in script, not in order of depth. The problem is actually that it already does that!

avatar image syclamoth · Nov 16, 2011 at 09:28 AM 0
Share

(I should mention that while the specific project I was working on when I asked this question has been finished now, I never really found anything better than a shitty workaround for this problem, so I'm still looking for a solution!)

avatar image jahroy · Nov 17, 2011 at 06:00 AM 0
Share

Here's a bad solution you may have already seen that probably won't help:

http://answers.unity3d.com/questions/59898/how-to-draw-gui-controls-on-top-of-each-other.html

avatar image fherbst · Nov 20, 2011 at 10:24 AM 0
Share

Another side note: the documentation for GUI.depth states that for this value to do anything, each depth layer needs its own script.

1 Reply

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

Answer by CHPedersen · Nov 16, 2011 at 10:37 AM

This problem is a total pain in the ass. It's been bothering people for a while, now. Most people refer to it as "GUI click through", and I've seen multiple questions attempt to address it, and very few reliable solutions.

I'm afraid the answer is that this is one of the pitfalls in Unity's GUI system that they simply haven't properly fixed yet, and therefore, people are left to resort to shitty workarounds (like you mentioned) instead of something robustly implemented in the framework.

One of the best (=least shitty) solutions I've seen talks about GUI.Button being broken in that it doesn't honor an indicator that was supposed to prevent it processing the GUI event when controls are layered. It provides a custom version of a GUI button that fixes this issue, and it's available in this forum post:

http://answers.unity3d.com/questions/16774/preventing-mouse-clicks-from-passing-through-gui-c.html

If you're using buttons to capture the button press in those DropDownLists, maybe it can be of use to you. If not, perhaps the way it fixes the button can work for your DropDownList as well.

Alternatively, you can use Event.Use() in order to make one script signal that it has spent a GUI event, and the event does not need to be processed by anyone else. But then you need to make sure you draw the lists in the order you want them to spend GUI events, (i.e. in GUI.depth ascending order), so that controls with lower GUI.depth (those drawn last) get to call Event.Use() first.

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 syclamoth · Nov 17, 2011 at 05:57 AM 0
Share

That last bit is a little tricky, I'm afraid- the entire point of the system depends on being able to make the calls in an arbitrary order, and leave the rest to the GUI system. In any case, thanks for the information- I'll try to implement some of this stuff in a reasonably general way.

avatar image CHPedersen · Nov 17, 2011 at 07:55 AM 0
Share

I know, it's annoying. :-/ If you do come up with a solution that somehow addresses this issue better than the ones I've found when researching it, please do post it. I'd be interested to see a proper workaround that doesn't trigger everyone's code-smell-detector. :-)

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

Using treeview OnGUI with GUIlayout 0 Answers

Method is called, but GUI doesn't show up 1 Answer

Using an On-Screen GUI Button to show a GUI? 1 Answer

Multiple Cars not working 1 Answer

Can you use GUIStyle with GUILayout? 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