Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
8
Question by Rafes · Aug 18, 2011 at 02:50 AM · inspectordebughidepublicinternal

Hide from inspector interface but not from the debug inspector?

Hi,

I want to be able to see public fields in the debug tab of the inspector even when using [HideInInspector], is this possible?

I hide items because they are public but for script access only. I don't hide them to make debugging harder ;p

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

4 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Rafes · Sep 28, 2011 at 06:45 PM

This is a follow-up to extend the current answer to my question for completeness...

1) The most direct answer is "No". That is not possible" but it IS possible to achieve the desired result by not using [HideInInspector] at all and instead use custom editor scripts if you want granular control over what appears in the inspector tab when not in debug mode. Debug will show all serializable and supported public fields. Using custom editor scripts frees up code interface design to focus only on code and not on what is shown in Unity (among countless other benefits and options)

2) The use of internal for managing how public a member is (oversimplified, but...`protected` for derived classes, internal for assemblies, public for everything): The assemblies seem to be split on items in Plugins, Editor and the rest of Assets, based on what I see in Visual Studio. This has been great for code interface design for plugins! For inspector interface design, I use custom editor scripts now though.

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 cregox · Aug 29, 2013 at 06:20 PM 0
Share

Awesome! But you really should use "back quotes" (not this '. to me, it's on the top most left key, above Tab and with tilde ~) for keywords such as internal and [HideInInspector]. It helps a lot for reading.

avatar image Rafes · Aug 29, 2013 at 07:30 PM 1
Share

back-ticks didn't seem to do it. I was hoping it would do fixed-width, as you mention, like restructuredText

avatar image cregox · Aug 29, 2013 at 07:35 PM 0
Share

Yes, I can see them. That's weird. They sure work for me!

 `  <-- this
avatar image Eric5h5 · Aug 29, 2013 at 08:14 PM 0
Share

I removed your "" tags. They don't do anything anyway; this site doesn't use any HT$$anonymous$$L formatting in text, and attempting to use HT$$anonymous$$L tags apparently causes stuff to break.

avatar image Rafes · Aug 30, 2013 at 12:53 AM 0
Share

I see it now. Thanks!

avatar image
14

Answer by slippdouglas · Dec 26, 2013 at 08:08 PM

Create two scripts:

`Assets/Plugins/HideInNormalInspectorAttribute.cs`:

 using UnityEngine;
 
 public class HideInNormalInspectorAttribute : PropertyAttribute {}

`Assets/Plugins/Editor/HideInNormalInspectorDrawer.cs`:

 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(HideInNormalInspectorAttribute))]
 class HideInNormalInspectorDrawer : PropertyDrawer
 {
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
         return 0f;
     }
     
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {}
 }

Now, in your script, adorn the field you wish to be public and hidden in the normal inspector (visible in the debug inspector) with the HideInNormalInspector attribute:

 // C#
 [HideInNormalInspector]
 public int debugOnlyInt = 5;

 // JS
 @HideInNormalInspector
 var debugOnlyInt : int = 5;

This works by using Unity's PropertyDrawer/PropertyAttribute mechanism to override the inspector GUI drawing for the attributed properties, then not drawing anything and specifying zero height (so it doesn't leave a blank space).  Since the debug inspector ignores all custom PropertyDrawers, the field will show up there.

Comment
Add comment · Show 3 · 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 cregox · Jan 10, 2014 at 02:12 PM 0
Share

This is yet the most awesome answer here! And it should be default in Unity...

avatar image Razorwings18 · Dec 30, 2014 at 08:46 PM 0
Share

This is a great workaround slippdouglas. Unfortunately, I should point out that it does not completely work for expandable fields (i.e. arrays, lists) since it does hide the VALUES, but not the LABEL or SIZ$$anonymous$$

Sorry I can't post an alternative since I'm not editor-savvy.

avatar image Xavier78 · Dec 31, 2018 at 05:24 AM 0
Share

Does someone know how to add arrays to this also?

avatar image
6

Answer by Eric5h5 · Aug 18, 2011 at 04:57 AM

Use "internal":

 internal int foo = 5;
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 Rafes · Aug 18, 2011 at 05:38 AM 0
Share

is internal basically public to everything in the game's namespace? It is internal to the "application" right? I'm still pretty new to C#. Sounds like an awesome trick. I don't really care, but I wonder if JS has something like this.

Edit: Tested and success! (not that I doubted you, just confir$$anonymous$$g)

avatar image Eric5h5 · Aug 18, 2011 at 05:52 AM 0
Share

Yes, in JS it's:

 internal var foo = 5;
avatar image TSorbera · Sep 28, 2011 at 06:24 PM 0
Share

"internal" is internal to the assembly it's built in. $$anonymous$$g. if you declare a variable internal that's in Standard Assets, it will only be visible to scripts in Standard Assets, not normal scripts or Editor scripts.

avatar image Rafes · Sep 28, 2011 at 06:46 PM 0
Share

I removed this as the accepted answer and wrote a more complete follow up simply because it didn't address everything implied in my original question.

avatar image
2

Answer by nschrag · Mar 30, 2012 at 09:12 PM

You could also use C# properties to make a private field publicly accessible to scripts but not the normal inspector.

 private int notEditable;
 public int NotEditable { get { return notEditable; } set { notEditable = value; } }
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 slippdouglas · Apr 15, 2014 at 12:44 PM 0
Share

This would only meet the OP's needs if notEditable showed up in the debug inspector. In order to accomplish that, you'd need [SerializeField] preceding it, but then you're back to square one— it shows up in both the normal and debug inspectors.

avatar image correia55 · Nov 09, 2018 at 04:21 PM 0
Share

This does work, the inspector shows private variables in Debug $$anonymous$$ode.

avatar image UncleAlias · Jul 21, 2020 at 09:14 PM 0
Share

I know this is old, but it shows up on Google, so for anyone else searching for this: use {get; set;}, like this:

 public int $$anonymous$$yInt {get; set;}

You don't need the private backing variable. It will show up in the Inspector in Debug mode as <$$anonymous$$yInt>, but not in normal mode.

avatar image sammmburr · Jan 20 at 08:48 PM 0
Share

This is still the best answer for solving OP's issue as well as adding a layer of security to publicly accessible variables, making them essentially read-only if we just use;

 private int notEditable;
 public int NotEditable { get { return notEditable }   };

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

13 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

Related Questions

Public Array of Files that can be assigned via Inspector 1 Answer

Public variable not showing in Inspector(Solved) 1 Answer

Making a minor change to Default inspector? 1 Answer

Filling a large public array in editor 1 Answer

Why do Public Variables overwrite a Scripts Default Value 2 Answers


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