• 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 TheYokai · Jan 30, 2014 at 09:35 AM · c#editoreditorguiserializedpropertyserializedobject

Changing Inspector's Serialized Property Label (With Code Sample)

I've been making progress with one of my first editor extensions / tools for my own personal use and perhaps asset store uploading. It works decently well, but I have a simple question... First, the code.

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomEditor(typeof(StandardBrush))]
 public class StandardBrushINS : Editor 
 {
     private SerializedObject standardBrush;
     private SerializedProperty width;
     private SerializedProperty length;
     private SerializedProperty height;
 
     void OnEnable()
     {
         StandardBrush tempTarget = (StandardBrush)target;
         tempTarget.GetComponent<MeshFilter>().hideFlags = HideFlags.HideInInspector;
         tempTarget.GetComponent<MeshRenderer> ().hideFlags = HideFlags.HideInInspector;
         standardBrush = new SerializedObject (target);
 
         width = standardBrush.FindProperty ("userDesiredWidth");
         length = standardBrush.FindProperty ("userDesiredLength");
         height = standardBrush.FindProperty ("userDesiredHeight");
     }
 
     public override void OnInspectorGUI () 
     {
         EditorGUIUtility.LookLikeControls();
         standardBrush.Update ();
         EditorGUILayout.PropertyField (width);
         EditorGUILayout.PropertyField (length);
         EditorGUILayout.PropertyField (height);
         standardBrush.ApplyModifiedProperties();
     }
 }

So this code works, it updates the properties of the target in real time. Perfect. However, I have an issue with the SerializedProperty's labels. They inherit a label next to the field that is essentially the name of the variable. In this case, "User Desired Width/Length/Height" appear next to each field. This is redundant for the client as the "User Desired" naming convention is used mostly to make code more legible (as I do various checks between the User Desired value and the Current value.)

If this were a EditorGUILayout.FloatField, I would be able to put in my desired "label" as a string before the target float variable (i.e. EditorGuiLayout.FloatField("width", target.userDesiredWidth) .) Is there an equivalent for SerializedProperty?

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 · Jan 30, 2014 at 02:39 PM 0
Share

Have you read the documentation for PropertyField?

avatar image TheYokai · Jan 30, 2014 at 06:08 PM 0
Share

Yes, I was thinking GUIContent would provide a solution, but unfortunately I kept getting an error trying to create a new GUIContent object.

1 Reply

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

Answer by Jamora · Jan 30, 2014 at 09:10 PM

You can create a new GUIContent to show a different label as follows:

 EditorGUILayout.PropertyField(serializedObject.FindProperty("myVariable"), new GUIContent("aDifferentLabel"));
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 TheYokai · Feb 05, 2014 at 05:03 AM 0
Share

That's strange. I tried that before and the Unity IDE was yelling at me. I ignored it and it still compiled correctly. I thought perhaps I was missing arguments. This is the answer, just thought I'd come back and let anyone else looking this up know.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Select custom object from a list via PopUp in custom editor for ScriptableObject 0 Answers

Undo a instantiated gameObject Editor Script C# 1 Answer

Type casting SerializedProperty.objectReferenceValue doesn't work? 3 Answers

Handling Undo/REdo in EditorWindow when editing DB record. 0 Answers


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