• 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
5
Question by vexe · Feb 02, 2014 at 01:57 PM · spaceeditorguieditorguilayoutobjectfieldoninspectorgui

EditorGUILayout.ObjectField redundant space between label and object field?

This pretty much says it all:

alt text

Look at all that redundant space between the label and the field. It looks so stupid. How to get rid of it? How to make it more compact?

Code:

 public override void OnInspectorGUI()
 {
     var use = target as SingleItemUse;

     GUILayout.Label("Item entry", EditorStyles.boldLabel);
     GUIHelper.HorizontalBlock(() =>
     {
         use.entry.placement = EditorGUILayout.ObjectField("Placement", use.entry.placement, typeof(Transform), false) as Transform;
         use.entry.item = EditorGUILayout.ObjectField("Item", use.entry.item, typeof(Item), false) as Item;
     });
 }

Thanks for any help.

fsm.png (6.0 kB)
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
13
Best Answer

Answer by ArkaneX · Feb 05, 2014 at 09:22 PM

Hi vexe :)

You can use EditorGUIUtility.labelWidth to control the space reserved for label. Changing it before calling each EditorGUILayout.ObjectField allows to set different widths for different labels.

Comment
Add comment · Show 5 · 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 vexe · Feb 06, 2014 at 08:44 AM 0
Share

Arkane for the save! - Thank you dear :) - However, I assume I have to cache the original width to restore later once I'm done, so that I don't affect preceding labels right?

avatar image vexe · Feb 06, 2014 at 08:45 AM 0
Share

Aaaannndd... Congrats on 10k!!! ;)

avatar image ArkaneX · Feb 06, 2014 at 09:36 AM 1
Share

Thx :)

You can cache and reassign original value, or (according to documentation) you can set it to 0 to restore default value.

avatar image IgorAherne · Oct 05, 2016 at 04:26 PM 0
Share

Awarded, m8. Additionally, might be trivial, but there is also "fieldWidth" :D

avatar image PatrickReynolds · May 10, 2017 at 03:22 PM 0
Share

Thank you for the answer. I know it was a while ago, but this just helped me immensely.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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

Related Questions

ReorderableList and object fields 2 Answers

Editor GUI TEXT On Inspector: How to add header text note in the inspector using a Custom Editor Inspector script ? 1 Answer

EditorGUILayout.ObjectField cannot be changed. 1 Answer

EditorGUILayout.ObjectField with Mecanim Animator 0 Answers

Button in EditorGUI / ScriptableWizard? 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