Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by cgeopapa · May 19, 2016 at 09:31 AM · enumeditorguicustom-inspectoreditorguilayout

drawdefaultinspector except of one variable??

Hello,

So say I have a script that makes a custom inspector for anotherone. The target script has many variables and depending on the enum value I select I want to hide 2 of them. In other words when my enum is set to A I want all the variables of my script to appear in the inspector, but when it is set to B I want to all the variables to appear except of 2.

Do I have to write one line of code for each variable at my custom inspector script or is there a way to say drawDefaultInspector except of those 2 variables?

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
Best Answer

Answer by FortisVenaliter · May 19, 2016 at 07:04 PM

As far as I know, yeah, you have to rewrite the whole inspector if you want to change the functionality of even one variable. Luckily, all of the predefined fields already have functions to display the same way they do normally.

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

Answer by Nition · Oct 18, 2019 at 12:06 AM

Instead of using DrawDefaultInspector(), use:

 DrawPropertiesExcluding(serializedObject, "myProperty", "myOtherProperty);
Comment
Add comment · Show 4 · 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 Bunny83 · Oct 18, 2019 at 10:02 AM 2
Share

Right and you don't have to rewrite the whole inspector even when you want to insert some GUI in between. You can simply iterate over the SerializedProperties:

     // untested.
     serializedObject.Update();
     var p = serializedObject.GetIterator();
     do
     {
         if (p.name != "NameYouWantToOmit")
             EditorGUILayout.PropertyField(p);
         if(p.name == "someProperty")
         {
             // Add extra GUI after "someProperty"
         }
     }
     while (p.NextVisible(true));
     serializedObject.Apply$$anonymous$$odifiedProperties();
avatar image Nition Bunny83 · Oct 20, 2019 at 09:40 PM 0
Share

Nice trick! I'd never thought of doing it that way.

avatar image Omti1990 · Oct 31, 2020 at 09:12 AM 0
Share

Some guy explains it really well here with an example: https://forum.unity.com/threads/hiding-inherited-public-variable-in-the-inspector.161828/#post-4689677

I just needed to copy the code relevant for me.

 using UnityEditor;
 
 [CustomEditor(typeof(Laser))]
 public class LaserEditor : Editor
 {
 
     
     public override void OnInspectorGUI()
     {
         serializedObject.Update();
         EditorGUI.BeginChangeCheck();
         DrawPropertiesExcluding(serializedObject, "firingCycleInterval");
         if (EditorGUI.EndChangeCheck())
             serializedObject.Apply$$anonymous$$odifiedProperties();
     }
 }
avatar image Sasune_Fair · May 03 at 06:38 AM 0
Share

This is an excellent way to draw an editor but exclude (and then replace) a few custom attributes. This answer needs to get out there more!!

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

46 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

Related Questions

What is the efficient way of showing variables depend on enum in custom inspector? 2 Answers

EditorGUILayout.EnumPopup giving me errors 1 Answer

Button in EditorGUI / ScriptableWizard? 1 Answer

Applying WordWrap to an existing Editor Text Field 0 Answers

Weird action in Unity editor when pressing the "E" key? 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