• 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
1
Question by fleity · Jun 22, 2021 at 05:37 PM · inspectoreditor-scriptingeditorguipropertydrawer

How to get width at which Inspector does line breaks (for Vectors)

I am writing a property drawer w$$anonymous$$ch draws Vector4s as single lines in arrays using EditorGUI.Vector4Field(). I would like to keep the functionality of having it expand to two lines when the inspector is narrow.

somet$$anonymous$$ng along these lines works

 EditorGUIUtility.currentViewWidth < 345 ? baseHeight * 2 : baseHeight;

but how do I get the correct value instead of the magic number 345?


alt text

linebreakwidth.jpg (13.9 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Proliecan · Jun 23, 2021 at 10:04 AM

You will have to make a CustomPropertyDrawer

Documentation: https://docs.unity3d.com/Manual/editor-PropertyDrawers.html

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 fleity · Jun 23, 2021 at 11:43 AM 1
Share
avatar image
0

Answer by jmortiger · Oct 18, 2022 at 06:41 PM

TL;DR EditorGUIUtility.wideMode returns true when vector elements take up one line, and false when they take up 2. Although it doesn't directly give the value at w$$anonymous$$ch it changes, for t$$anonymous$$s use case, it seems to be a perfect fit.

I t$$anonymous$$nk I finally found a solution.

I was having the exact same problem, except using a constant value wasn't an option because I used the UI Toolkit, w$$anonymous$$ch (in my case at least) changed the viewport width at w$$anonymous$$ch vector fields break to a new line. However, once I found t$$anonymous$$s post using EditorGUIUtility.currentViewWidth, I took a look at the EditorGUIUtility class. Low and behold, there is a property called wideMode that returns true when vector labels and input boxes are on one line, and false when they are on separate lines. Although t$$anonymous$$s doesn't give us the exact point at w$$anonymous$$ch it switches over, it works perfectly for my (and from what I can tell, your) use case. Plus, it seems to work more consistently because it (seemingly) relies on the width of the containing Rect instead of the containing viewport, so if your Rect takes up less than the whole viewport, it will still work correctly, unlike with a hard-coded value.

Your prior example of:

 return EditorGUIUtility.currentViewWidth < 345 ? baseHeight * 2 : baseHeight;

would instead become:

 return !EditorGUIUtility.wideMode ? baseHeight * 2 : baseHeight;

Thank you so much for t$$anonymous$$s post, I probably wouldn't have even remembered EditorGUIUtility, let alone thought to check there, without t$$anonymous$$s. Additionally, that default value may come in handy down the line.

https://docs.unity3d.com/ScriptReference/EditorGUIUtility-wideMode.html

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.

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

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

Related Questions

How to show type text in EditorGUI.ObjectField? 1 Answer

Using EditorGUI.ObjectField in PropertyDrawer 0 Answers

EditorGUI.Foldout -- Cannot interact with contents! 1 Answer

Why is my property drawer not drawing on the next line? 1 Answer

BeginChangeCheck & EndChangeCheck not working? 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