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 AW0610AUT · Feb 09, 2014 at 11:51 AM · javascriptguifpsgrouplow

GUI.BeginGroup = 1-2 fps

Hello, i have the following code. It works like this. When i move my mouse over a asteroid it opens a gui window at the mouse pos. In this window i will display the content of the Asteroid (the var´s at the bottom). It´s all working fine except the fact that when i insert GUI.EndGroup (); it runs with about 1-2 fps. And also it displays a gui window in the top left that shouldnd be there. If i leave the GUI.EndGroup away i get an error that says "Invalid GUIClip stack popping"

Any ideas why?

Thanks in advance, Alex

Here is the code: var initialColor : Color; var GUIopen : boolean = false; var boxPos: Vector3;

 var H : float;
 var O : float;
 var C : float;
 var Fe : float;
 var Au : float;
  
 function Start()
 {
    initialColor = renderer.material.color;
 }
  
 
 
 
 
 function OnMouseOver()
 {
    renderer.material.color = Color.green;
    
    boxPos.x = Input.mousePosition.x;
    boxPos.y = Screen.height - Input.mousePosition.y;
    GUIopen = true;
    
 }
  
 function OnMouseExit()
 {
    renderer.material.color = initialColor;
    GUIopen = false;
 }
 
 function OnGUI ()
 {
  if (GUIopen)
         GUI.BeginGroup (Rect (boxPos.x, boxPos.y, 150, 200));
         GUI.Box (Rect (0,0,150,200), "Content:" );
         //GUI.EndGroup(); //if i put that there it runs very slow if not i get the error as mentioned above
 }
 function Update()
 {
 
 
 //H = GetComponent(AsteroidResourceGen).H ;
 //O = GetComponent(AsteroidResourceGen).O ;
 //C = GetComponent(AsteroidResourceGen).C ;
 //Fe = GetComponent(AsteroidResourceGen).Fe ;
 //Au = GetComponent(AsteroidResourceGen).Au ;
 
 
 }
 
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 Jamora · Feb 09, 2014 at 12:56 PM 0
Share

I suspect it's because you have a material change in On$$anonymous$$ouseOver (each frame the mouse is OVER your collider/GUIElement). On$$anonymous$$ouseEnter could, maybe, work better.

avatar image AW0610AUT · Feb 09, 2014 at 01:33 PM 0
Share

i had the script working without the gui stuff and it worked like this perfectly. So i dont think it is because of that. It has to do with the Gui function stuff. hmm any other ideas?

1 Reply

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

Answer by Hoeloe · Feb 09, 2014 at 02:04 PM

Your problem is syntactic.

Let me address these lines:

 if (GUIopen)
   GUI.BeginGroup (Rect (boxPos.x, boxPos.y, 150, 200));
   GUI.Box (Rect (0,0,150,200), "Content:" );
   GUI.EndGroup();

Your problem is not GUI.EndGroup(), but actually the conditional above. Let's address the syntax of conditional statements.

Conditionals have two basic forms, that I call "block conditionals" and "line conditionals". Most conditional statements will be block conditionals. These look like this:

 if (condition)
 {
   //do a thing
 }

If the condition is true here, everything inside the following block will be executed, otherwise it will be skipped.

Now, line conditionals are slightly different. They look like this:

 if(condition)
   //do this line

I call these "line" conditionals because they are designed for short statements. The semantics of conditional statements is that if you don't specify where the conditional block begins and ends, it is assumed to be one line long. So, for example, this code:

 if(x < 5)
 {
   x ++;
   y = 4;
 }

Will NOT be the same as this code:

 if(x < 5)
   x ++;
 y = 4;

If we run both of those with x = 6 and y = 0, the first will produce x = 6, y = 0, while the second will produce x = 6, y = 4, because the line conditional does not include the assignment in its scope.

So, with this in mind, let's take another look at your code:

 if (GUIopen)
   GUI.BeginGroup (Rect (boxPos.x, boxPos.y, 150, 200));
   GUI.Box (Rect (0,0,150,200), "Content:" );
   GUI.EndGroup();

Now, I don't see a block definition anywhere (that's the curly brackets), so this must be a line conditional.

Oops.

What this means is that your program would be better written like this:

 if (GUIopen)
   GUI.BeginGroup (Rect (boxPos.x, boxPos.y, 150, 200));
 GUI.Box (Rect (0,0,150,200), "Content:" );
 GUI.EndGroup();

Which is functionally identical to this:

 if (GUIopen)
 {
   GUI.BeginGroup (Rect (boxPos.x, boxPos.y, 150, 200));
 }
 GUI.Box (Rect (0,0,150,200), "Content:" );
 GUI.EndGroup();

Now you might start to see what is causing the problem. If GUIopen is true, then this will execute just fine. If GUIopen is false, however, then you skip the BeginGroup call. This doesn't cause a problem when calling GUI.Box, but you then call GUI.EndGroup. However, you haven't actually started a group under these circumstances, so you are trying to pop something off the stack that doesn't exist.

What was that error you said you got?

 Invalid GUIClip stack popping

The frame rate drop is likely actually from the console printing out hundreds and hundreds of error messages.

Hopefully this has taught you a thing or two, and you can see how to fix 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 AW0610AUT · Feb 09, 2014 at 02:18 PM 0
Share

Ahh ok. I never knew that there was a diffrence between these if statments. Thanks for the great explanation.

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

20 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

Related Questions

The next problem with gui. 1 Answer

Showing text near object 1 Answer

Setting Scroll View Width GUILayout 1 Answer

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers

Circle GUI Button, Javascript? 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