- Home /
Additional information on mouseover in the inspector
Hey,
Some standard Unity scripts shows additional information when you mouseover the variable in the inspector. Does anyone know if there is a standard way of displaying this information on custom variables? (Both using public variables and/or Editor script)
See attached image on what i am trying to replicate.

Answer by Bryan-Legend · Nov 20, 2014 at 07:35 PM
As of Unity 4.5 or later just do this. The tooltip attribute is now built in.
 public class SomeClass : MonoBehaviour
 {
     [Tooltip("This is a great tooltip")]
     public int someVariable = 5;
 }
Answer by trololo · Aug 09, 2013 at 10:26 AM
 GUIContent content = new GUIContent("Text", "Info Pop-up");
 int test = EditorGUILayout.IntField(content, test, GUILayout.Width(100f));
The tooltip attribute method works great for static tips, but this is the way to go if your tooltip need to change dynamically. Thanks trololo.
Answer by Lev-Lukomskyi · Apr 12, 2014 at 09:49 PM
You can add tooltips easily with new Unity PropertyDrawers feature:
Assets/Scripts/TooltipAttribute.cs:
 using UnityEngine;
 
 public class TooltipAttribute : PropertyAttribute
 {
     public readonly string text;
 
     public TooltipAttribute(string text)
     {
         this.text = text;
     }
 }
Assets/Editor/TooltipDrawer.cs:
 using UnityEditor;
 using UnityEngine;
 
 [CustomPropertyDrawer(typeof(TooltipAttribute))]
 public class TooltipDrawer : PropertyDrawer
 {
     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
     {
         var atr = (TooltipAttribute) attribute;
         var content = new GUIContent(label.text, atr.text);
         EditorGUI.PropertyField(position, prop, content);
     }
 }
And use:
 public class SomeClass : MonoBehaviour
 {
     [Tooltip("This is a great tooltip")]
     public int someVariable = 5;
 }
For anyone stumbling upon this solution who has Unity 4.5 or later, you can now use the [Tooltip("This is my tooltip")] attribute without using any of the plugin/setup code (i.e. you don't TooltipAttribute.cs nor TooltipDrawer.cs any more)
thanks for this -- working perfectly on Unity Pro 4.3. slight problem, this requires using Unity Engine which works fine during runtime in the editor. however building for iOS throws a compiler error (as expected) -- thus I end up wrapping all my tool tips in pre compiler tags #if UNITY_EDITOR [ToolTip("some tooltip")] #endif
this is a nooby question .. but what's the full method call for [Tooltip("some tooltip")] ? UnityEngine.Tools.[Tooltip("some tool tip")] doesn't work, neither does [UnityEngine.Tools.Tooltip("some tool tip")] (neither does UnityEngine.PropertyDrawer... etc
Answer by skovacs1 · Dec 07, 2010 at 07:35 PM
For that you would need to define a custom editor with a EditorGUILayout.PropertyField which is passed a GUIContent with the appropriate tooltip set.
Great! I somehow missed the GUIContent variable and only used the overloaded method that takes a String label ins$$anonymous$$d. To bad that it don't work (out-of-the-box) on some EditorGuiLayout functions like Vector3Field but that's not a big problem. Thanks!
Any chance you could give us some sample code template?
Your answer
 
 
             Follow this Question
Related Questions
Retrieve Variable's [Tooltip()] Property From a Custom Inspector (C#) 2 Answers
Draw specific Object Inspector into Rect 1 Answer
How can a class inherit from another that is modified by editor 1 Answer
How should I serialize data that is also editable in the Inspector? 2 Answers
Customizing Inspector variables. 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                