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
1
Question by spaceshooter · Dec 17, 2010 at 02:53 PM · guiguilayouttooltip

Why can't I get my tooltip to show only when there is a tooltip set?

If I use GUILayout, inside an if statement in OnGUI I get the following error:

ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint

Any idea how to use GUILayout inside an if statement? Thanks!

GUI.Box(new Rect(5, 35, 110, 75), new GUIContent("Box", "this box has a tooltip"));

 if (GUI.tooltip != "") // <- This causes problems
 {
     var rect = new Rect(Screen.width / 2, Screen.height / 2, 300, 300);
     GUILayout.BeginArea(rect);
     GUILayout.Button("I am completely inside an Area");
     GUILayout.EndArea();
 }

Comment
Add comment · Show 8
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 Statement · Dec 17, 2010 at 03:44 PM 0
Share

Paste the if-statement....

avatar image The_r0nin · Dec 17, 2010 at 03:45 PM 0
Share

Yes... especially if you don't have an additional GUILayout outside of the if...

avatar image Statement · Dec 17, 2010 at 03:48 PM 0
Share

OnGUI is called multiple times per frame and expects the program flow to be static for some of the different -events-. Basically it's safe to switch flow on if (GUILayout.Button()) and other GUI calls, but if you're checking if a key is pressed you might run into troubles. Ins$$anonymous$$d, try doing that in Update and set state variables. Or read in depth about how the GUI system works in the manual. In my personal opinion (and off topic rant), unitys gui is a real horror show where tons can go wrong and it's often not immediately clear what is the cause.

avatar image spaceshooter · Dec 17, 2010 at 04:02 PM 0
Share

It is just: if (GUI.tooltip != "")

avatar image spaceshooter · Dec 17, 2010 at 04:11 PM 0
Share

Added the full OnGUI example to the main post.

Show more comments

2 Replies

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

Answer by Mike 3 · Dec 17, 2010 at 04:36 PM

GUILayout is a pain like that sometimes, and this case is one which won't be easily solvable.

What you could do is swap to GUI for just the tooltip - the code would be cleaner for your example anyway

if (GUI.tooltip != "")
{
    var rect = new Rect(Screen.width / 2, Screen.height / 2, 300, 300);
    GUI.Button(rect, GUI.tooltip);
}

Alternatively, you could use GUILayout to calculate the rects (by using GetRect), and then pushing them into the above function to actually draw the visible item

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 spaceshooter · Dec 17, 2010 at 04:48 PM 0
Share

Looks like I will be using GUI ins$$anonymous$$d, thanks!

avatar image Statement · Dec 17, 2010 at 04:50 PM 0
Share

Ah! Awesome, so it was just the GUILayout methods that cause this problem? Wow, thanks a ton!

avatar image spaceshooter · Dec 17, 2010 at 05:19 PM 0
Share

I have a box and 2 labels (text and a texture) so far and it seems to work :)

avatar image
1

Answer by Eric5h5 · Dec 17, 2010 at 07:26 PM

I've dealt with stuff like this before; the solution is to check for EventType.Repaint, and use a separate variable that tracks whether the tooltip is active or not, so the layout stuff can be properly computed in the right order:

private var tooltipActive = false;

function OnGUI () { GUI.Box(new Rect(5, 35, 110, 75), new GUIContent("Box", "this box has a tooltip"));

 if (tooltipActive)
 {
     var rect = new Rect(Screen.width / 2, Screen.height / 2, 300, 300);
     GUILayout.BeginArea(rect);
     GUILayout.Button("I am completely inside an Area");
     GUILayout.EndArea();
 }

 if (Event.current.type == EventType.Repaint)
     tooltipActive = GUI.tooltip != "";

}

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

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

No one has followed this question yet.

Related Questions

GUILayout ArgumentException when combining with GUI.Tooltip 1 Answer

Displaying a tooltip with GUILayout.Window 1 Answer

Text Alignment 2 Answers

Help with GUILayout and tooltip(C#) 1 Answer

For Loop GUILayout.Label Problems 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