How to hide field name in inspector

I’ve seen this done on the inspector for volume profiles. There’s a checkbox next to a field that when checked, enables the field, and disables it otherwise. But there’s no variable name associated with this checkbox.

image

So I want to mimic this effect. I want to have a bool that determines if the associated property is used in my function, but I don’t want that bool to take up a whole line in the inspector. How can I hide the name and have just the checkbox next to the field?

Unfortunately Unity doesn’t provide this as a ready to use attribute (except for one lucky case) , so if you want that for your component you’ll have to make a custom editor that draws the field as “disabled”.
Now for the lucky case , if you’re doing XR stuff , the closest thing you can get is using the [ReadOnly] attribute in the Unity.XR.CoreUtils namespace

Well, you can try using this…

Do change the MyComponent And add the last part to your script.

using UnityEditor;
using UnityEngine;

public class MyComponent : MonoBehaviour
{
    internal bool myBool;
}

[CustomEditor(typeof(MyComponent))]  // Replace MyComponent with the name of your script.
public class EDITOR : Editor
{
    public override void OnInspectorGUI()
    {
        MyComponent myComponent = (MyComponent)target;

        // Display a checkbox without a label
        myComponent.myBool = EditorGUILayout.Toggle(myComponent.myBool);

        // The rest of the default inspector GUI
        DrawDefaultInspector();
    }
}

You could create a struct (even a generic one) that holds both your value and the enable boolean, then make a custom PropertyDrawer for that struct that puts both PropertyFields in one line. The other option would be to make a completely custom Editor (by extending UnityEditor.Editor class with CustomEditor attribute) and draw all UI elements in your own way.