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 flamy · May 07, 2014 at 07:45 AM · guigui-problemguiwindow

GUI window gets drawn behind other gui elements.

This a strange bug where GUI window of mine gets drawn behind other elements of gui.

PS: all the elements are drawn from same file and irrespective of the GL contents, it still gets drawn behind the other elements. especially begin groups / boxes. Tried everything from changing drawing order.

alt text

alt text

guibug.png (42.0 kB)
guibug1.png (72.0 kB)
Comment
Add comment · Show 4
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 KiraSensei · May 07, 2014 at 07:52 AM 0
Share

Could you show us the code you use for 3 windows that overlap themselves, and tell us what code corresponds to which window ?

avatar image flamy · May 07, 2014 at 09:04 AM 0
Share

it is a bit more complicated actually and the logic resides across various files but gets called from a single OnGUI function...

and only of of it is window which you see at the bottom of the graph.

avatar image flamy · May 07, 2014 at 09:06 AM 0
Share

assume that each component u see in the window comes from a different file but the manager calls all these files from its ongui

avatar image flamy · May 07, 2014 at 09:25 AM 0
Share
 void OnGUI ()
     {
         GUI.depth = 2;
 
         foreach(GUIPage page in allPages)
         {
             page.DrawGUIObject(Vector2.zero);
         } 
 
     }


the above is the script from manager that calls all the gui elements.....

and the below is where the gui elements gets drawn for each page (a page can be a begin area or window or might refer global gui as well!)

 public override void DrawGUIObject (Vector2 offset)
 {

     objectsList.RemoveAll(obj=>obj==null);

     bool pageEnabled = false;


     pageEnabled = (parentPage == null)?isEnabled:parentPage.isEnabled && isEnabled;
     offset = (parentPage == null)?Vector2.zero:parentPage.boundingRect.Top();

     Event e = Event.current;

     if(pageEnabled )
     {
         if(pageType != GUIPageType.Window)
         {

             if(hasArea)
             {
                 if(pageType == GUIPageType.BeginAreaWithBG)
                 {
                     GUI.Box(boundingRect.SubstractWith (offset),"");
                 }
                 else if(pageType == GUIPageType.RoundedCorners)
                 {
                     if(e.type == EventType.repaint)
                     {
                         GLExtensions.GLDraw.DrawRoundedBox(boundingRect.SubstractWith (offset),boundingRect.width*0.075f,Color.white,boundingRect.width*0.0025f);
                     }
                 }
                 GUI.BeginGroup(boundingRect.SubstractWith (offset));
             }
             if( !isAutoLayout)
             {
                 GUISkin skinBckp = GUI.skin;

                 if(skin != null)
                 {
                     GUI.skin = skin;
                 }

                 foreach( GUIObject obj  in objectsList)
                 {
                     if(obj!= null)
                         {
 //                        Debug.Log(obj.name);
                             if(obj.enabled  && obj.GetType() != typeof(GUIPage) )
                             {
                                 obj.DrawGUIObject( hasArea ? boundingRect.SubstractWith (offset).Top() : Vector2.zero);
                             }
                         }
                     }
                 GUI.skin = skinBckp;

             }

             if(hasArea)
             {
                 GUI.EndGroup();
             }
         }
         else
         {
             GUI.Window(depth,boundingRect,Window,_name);       //Note that for windows, ID will be taken from depth!
         }
     }
 }

 void Window(int id )
 {
     foreach( GUIObject obj  in objectsList)
     {
         if(obj != null)
         {
             if(obj.isEnabled)
             {

                 obj.DrawGUIObject(boundingRect.Top());
         //        Event.current.Use();
             }
         }

     }
 }

2 Replies

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

Answer by flamy · May 14, 2014 at 06:48 AM

It is some bug with unity or the way GUI windows work! i dont know but the problem was with events of unity3d, When GUI Layout is getting called, the GUI window is supposed to be drawn, otherwise the window wont be displayed. And also repaint for the window gets calls as soon as first call to GUI.Window is being made that is the layouting event, so the window gets drawn first and then the other objects repaint event, hence the window goes behind everything.

this doesnt happen when I tried to call the whole gui from same script! But happens when i have the gui components across different scripts and try to call all of them from a single ongui.

And i solved it by using this

 if(e.type == EventType.layout)
     return;

for other components and by calling GUI window as the last call.

Still not clear on why this happens but will mark this as answer until i get an exact one!

Comment
Add comment · 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
0

Answer by Kacheek · May 07, 2014 at 08:00 AM

without the code i can unfortunaly not really help but i think it may help if i tell you that the gui elements are drawn in the order you type the code

for example

draw gui A;

draw gui B;

itll first draw gui A and then gui B on top of it

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 flamy · May 07, 2014 at 09:02 AM 0
Share

I know that very well i am calling the gui window at the end of all calls

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

22 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

Related Questions

GUI clean last frame 1 Answer

Impossible: 2 toolbars show being clicked at the same time! 1 Answer

Edit the color/properties of Gui border 0 Answers

GUI.Window called 2 frames ahead than OnGUI? 0 Answers

Can I make my GUI Buttons appear OVER a GUI Window? 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