• 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 r3david · Jun 22, 2016 at 05:10 AM · buttoneditor-scriptingeditorguipropertydrawerfoldout

EditorGUI.Foldout consumes click so GUI.Button doesnt work when inside of foldout region.

I am writing a custom property drawer, and I have a EditorGUI.Foldout which when unfolded has inside a GUI.Button. It turns out the button doesnt receive any clicks, cause the Foldout region consumes its click event. Any workaround?, or anything I can do to make clicks to be received by the button inside the foldout region?

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 lulitd · Jul 25, 2017 at 07:10 PM

I recently encountered this problem.

I solved it by adjusting the height of the rect I pass in. The area that is clickable for the foldout is determined by the rect. I made it so that only the height of the label is clickable.

         private const float buttonSize= 45F;
         private bool showFoldout = false;
 
         public override void OnGUI(Rect container, SerializedProperty property, GUIContent label)
         { 
 
             EditorGUI.BeginProperty(container, label, property);

             // set the width and/or height of the rect that you pass into the foldout to not cover your buttons. 
           // the orginal container.height uses the get property height. 
           
             container.height = EditorGUIUtility.singleLineHeight;  
 
             showFoldout = EditorGUI.Foldout(container, showFoldout, label, false, EditorStyles.foldout);
 
             if (showFoldout)
             {
 // insert ur layout here.
 }
 
 EditorGUI.EndProperty();
 }
 
 
  public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
         {
             return (showFoldout)?buttonHeight* 3f + EditorGUIUtility.singleLineHeight * 3 : EditorGUIUtility.singleLineHeight;
            
         }






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 HarvesteR · Nov 04, 2020 at 06:30 PM 0
Share

Thank you! I was banging my head against this custom inspector that wouldn't let me focus the input fields inside a foldout. Turns out the foldout rect height needs to be set to single line, otherwise it will invisibly cover its contents and make them unresponsive.

 rect.height = EditorGUIUtility.singleLineHeight;
 property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, label);

Cheers!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Property Drawer and Children 3 Answers

GetPropertyHeight infinite recursion on drawer 1 Answer

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

Why is my property drawer not drawing on the next line? 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