Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Glurth · Nov 08, 2016 at 06:52 PM · uicustom editorlayoutrectpropertydrawer

How to properly deal with EditorGUI.indentLevel in custom PropertyDrawers

If I have the following code snippet in a CustomEditor

 EditorGUI.indentLevel++;
    EditorGUILayout.PropertyField(testProperty);
 EditorGUI.indentLevel--;


If the testProperty’s CustomPropertyDrawer uses say..

 flag=EditorGUI.Foldout(position,flag,…)

Then the graphical layout for the foldout button does NOT match the clickable area of the foldout button. I need to click to the LEFT of my visible foldout button, in order for the click to be detected.

Why does EditorGUI.indentLevel>0 cause such a misalignment between the drawn location vs. the clickable location, and what is the proper way to deal with this?

Do I actually need to manually/temporarily override the EditorGUI.indetLevel value, and recompute the “position” Rect, that is passed to my CustomPropertyDrawer , like so? (I feel like this should be happening for me, automatically. In fact, it seems like it halfway IS.)

 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
    int recordedIndentLevel=EditorGUI.indentLevel;
    position.xMin += EditorGUI.indentLevel * 10.0f;  //FYI: 10.0f is incorrect, not sure yet how to get actual indent size
    EditorGUI.indentLevel = 0;
 
    //draw stuff using position rect
    flag=EditorGUI.Foldout(position,flag,…)
 
    EditorGUI.indentLevel = recordedIndentLevel;
 }
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
6
Best Answer

Answer by Ash-Blue · Sep 06, 2017 at 08:59 PM

Looks like you need to call var indentedRect = EditorGUI.IndentedRect(position); to get the indent you're looking for.

Comment
Add comment · Show 2 · 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 Glurth · Sep 17, 2017 at 05:22 PM 2
Share

This is correct. However, one must ALSO set the indentLevel to 0, before calling foldout. In addition, to get the foldout in the ACTUAL indented rect (as opposed to just to the left of it), and have it heed the foldout function's allowClickOnLabel parameter, one must ALSO set https://docs.unity3d.com/ScriptReference/EditorGUIUtility-hierarchy$$anonymous$$ode.html to false.

avatar image Eldoir Glurth · Feb 24, 2021 at 09:27 PM 0
Share

THANKS! EditorGUI.IndentedRect was fixing most of my issue, but ALSO adding EditorGUI.indentLevel = 0 before my foldout display has completely fixed it!

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

85 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

Related Questions

PropertyDrawer inserting large space for list 0 Answers

Draw on Multiple Lines with EditorGUI 1 Answer

Horizontal Layout Group making a Scroll Rect's Content rect width to be negative 1 Answer

Fill empty space in parent in UI Layout 1 Answer

Translate GetWorldCorners (new UI) to Viewport for a camera rect 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