- Home /
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
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.
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.
back-ticks didn't seem to do it. I was hoping it would do fixed-width, as you mention, like restructuredText
Yes, I can see them. That's weird. They sure work for me!
` <-- this
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.
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.
This is yet the most awesome answer here! And it should be default in Unity...
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.
Answer by Eric5h5 · Aug 18, 2011 at 04:57 AM
Use "internal":
internal int foo = 5;
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)
"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.
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.
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; } }
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.
This does work, the inspector shows private variables in Debug $$anonymous$$ode.
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.
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
Follow this Question
Related Questions
Public variable not appearing in the inspector (C#) 2 Answers
Hide null scripts in the inspector 1 Answer
is there a way to change the public inspector details at runtime 1 Answer
How to set a public variable to a gameObject in the inspector through coding 1 Answer
Warning messages are turning into Internal Compiler Errors...? 6 Answers