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
0
Question by dozer · Aug 28, 2011 at 02:47 AM · guiwindowguilayouttooltip

Displaying a tooltip with GUILayout.Window

I'm having trouble getting GUI.tooltip to work well with GUI Windows and GUILayout. There are two issues:

  1. It seems that GUI.tooltip is only valid inside the Window's GUI function, but I need to be able to show a tooltip that extends outside the boundaries of the Window.

  2. The tooltip needs to display even if the window is not focused.

Because I'm using GUILayout instead of GUI, I can't check if the mouse position is inside the component's rectangle.If anyone could show me how to get the below code working, it would be hugely appreciated!

 using UnityEngine;

 public class App : MonoBehaviour {
     Rect win1Rect = new Rect(20, 20, 150, 150);
   
     void OnGUI () {
         GUILayout.BeginArea(win1Rect);
         win1Rect = GUI.Window(0, win1Rect, DoWin1, "Win1");
         GUILayout.EndArea();

         if (GUI.tooltip != "") {
             // Does not work because it's outside of DoWin1
             GUI.Label(new Rect(0, 0, 100, 20), GUI.tooltip);
         }
     }
   
     void DoWin1 (int windowId) {
         GUILayout.BeginVertical();
         GUILayout.Button(new GUIContent("Button", "Win1 tooltip"));
         GUILayout.EndVertical();
     }
 }
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

1 Reply

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

Answer by Bunny83 · Aug 28, 2011 at 12:26 PM

GUI.Window (You should actually use GUILayout.Window) works a bit different than other GUI controls. Unity "saves" the data you provide (id,rect,callback, title) internally and handles the windows after OnGUI is finished. That's why you have to use a callback function so Unity can execute the window stuff when it needs to.

To access the tooltip from inside a window outside you have to store it somewhere outside.

Just do something like:

using UnityEngine;

public class App : MonoBehaviour { Rect win1Rect = new Rect(20, 20, 150, 150); string win1ToolTip = "";

 void OnGUI () {
     GUILayout.BeginArea(win1Rect);
     win1Rect = GUI.Window(0, win1Rect, DoWin1, "Win1");
     GUILayout.EndArea();

     if (win1ToolTip != "") {
         // Does not work because it's outside of DoWin1
         GUI.Label(new Rect(0, 0, 100, 20), win1ToolTip );
     }
 }

 void DoWin1 (int windowId) {
     GUILayout.BeginVertical();
     GUILayout.Button(new GUIContent("Button", "Win1 tooltip"));
     GUILayout.EndVertical();
     if (Event.current.type == EventType.Repaint)
         win1ToolTip = GUI.tooltip;
 }

}

It will delay the reaction by one frame because the tooltip change will take affect next frame but usually you can't see such a delay.

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 dozer · Aug 29, 2011 at 01:19 AM 0
Share

Thanks for taking the time to respond. Unfortunately, this code didn't work for me (even after changing the label to use win1ToolTip ins$$anonymous$$d of GUI.tooltip). However, what I ended up doing is only setting the value of win1ToolTip if onGUI is in the repaint frame: if (Event.current.type == EventType.Repaint).

I guess now it will be a matter of creating a new window that holds this tooltip, and making sure it always renders on top of all other GUI components.

Thanks for pointing me in the right direction.

avatar image Bunny83 · Aug 30, 2011 at 12:05 PM 0
Share

Sorry for the typo ;) and yes, you're right you should only read the tooltip in repaint. I've edited my answer.

avatar image CHPedersen · Sep 08, 2011 at 03:10 PM 0
Share

This just helped me a lot. It would've taken me ages to figure out why the tooltip was empty outside the window without this. :)

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

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

GUI.Window error. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync. 0 Answers

Having a GUILayout Window position immediately at screen center 5 Answers

Windows that do not take priority over other GUI elements 0 Answers

GUI Window Render Priority 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