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

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 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.

Use “internal”:

internal int foo = 5;

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; } }

UI Elements version

using UnityEngine;
using UnityEngine.UIElements;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class HideInNormalInspectorAttribute : PropertyAttribute 
{
    public HideInNormalInspectorAttribute() { }
}

#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(HideInNormalInspectorAttribute))]
public class HideInNormalInspectorAttributeDrawer : PropertyDrawer
{
    public override VisualElement CreatePropertyGUI(SerializedProperty property) 
    {
        var mode = ActiveEditorTracker.sharedTracker.inspectorMode;
        if (mode == InspectorMode.Normal)
            return new VisualElement();
        else
            return base.CreatePropertyGUI(property);
    }
}
#endif