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
2
Question by Moohasha · Dec 26, 2014 at 04:16 PM · propertiespropertydrawer

How can I show tooltip on property field?

I am writing a PropertyDrawer for a custom class that I have and I'm just drawing property fields with no labels. So all that gets drawn are an enum popup and a float slider.

I want to display a tooltip when you mouse over the enum popup that provides a description of the selected enum value, so I created a GUIContent with no label and a tooltip, but this didn't work. It appears the tooltip in GUIContent only applies to the label.

Is it possible to display a tooltip when the user mouses over a property field that doesn't have a label?

 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(RequiredSkill))]
 public class RequiredSkillDrawer : PropertyDrawer 
 {
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
     {
         SerializedProperty skill = property.FindPropertyRelative("skill");
         SerializedProperty level = property.FindPropertyRelative("level");
 
         // Get the rectangles for the properties
         Rect skillRect = new Rect(position.x, position.y, position.width/2-2, position.height);
         Rect levelRect = new Rect(position.x + skillRect.width + 4, position.y, position.width/2-2, position.height);
 
         // Get the tooltip for the currently selected skill
         string tooltip = Skills.Description((Skills.Type)skill.enumValueIndex);
 
         // Draw the properties
         EditorGUI.PropertyField(skillRect, skill, new GUIContent("", tooltip));
         EditorGUI.PropertyField(levelRect, level, GUIContent.none);
     }
 }
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

4 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by Moohasha · Dec 26, 2014 at 04:21 PM

LOL Of course, I found a solution about 30 seconds after posting. I just created a LabelField right after my PropertyField that has the same Rect so that it takes up the same space on the screen, but has no text. So when you mouse over the EnumPopup, you're really mousing over the LabelField that can't be seens and that displays the tooltip. =P

 // Draw the properties
 EditorGUI.PropertyField(skillRect, skill, GUIContent.none);
 EditorGUI.PropertyField(levelRect, level, GUIContent.none);
 EditorGUI.LabelField(skillRect, new GUIContent("", tooltip)); // <-- Displays 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
avatar image
2

Answer by Ross_B · Oct 06, 2016 at 01:27 PM

You can use a normal Tooltip on the serialized field and the property field will render it on hover.

In the object being inspected:

 [Tooltip("My tooltip")]
 [SerializeField] protected Transform transform;

In custom inspector:

  SerializedProperty serTransform = serializedObject.FindProperty("transform");
  //...

  serializedObject.Update();
  EditorGUILayout.PropertyField(serTransform);
  serializedObject.ApplyModifiedProperties();
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
2

Answer by turbanov · Oct 16, 2017 at 11:30 AM

Try getting a TooltipAttribute in your Drawer from this.fieldInfo.Attributes like so:

 var tt = fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true).FirstOrDefault()
                      as TooltipAttribute;
 if (tt != null) label.tooltip = tt.tooltip;
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 Novack · Jul 05, 2018 at 04:31 PM 0
Share

Yes, this works perfectly. Im using it like this:

 var tooltipAttribute = fieldInfo.GetAttribute<TooltipAttribute>();
 label.tooltip = tooltipAttribute != null ? tooltipAttribute.tooltip : "";


Thanks!

avatar image
0

Answer by cmersereau · Apr 29 at 06:52 PM

If you found yourself here because you are trying to access the tooltip that already exists on a field, and are doing custom drawing in a custom editor window instead of a property drawer, you are able to access the tooltip string from the serialized property.

 var tooltipString = mySerializedObject.FindProperty("myFieldName").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

33 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I correctly draw properties instead of fields in a custom property drawer? 0 Answers

How to get the target object value from a PropertyDrawer for an array of objects? 1 Answer

Using DuplicateCommand and DeleteCommand with Properties 0 Answers

Caching data for a PropertyDrawer 1 Answer

Accessing properties with spaces? 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