Toolbox controls in the Inspector
The value controls of the toolbox derive from BaseField<T>, so they work in the Unity Inspector too. Bind a control to a serialized field of the same type, and the Inspector fills it and writes each edit back, with undo, to each selected object.
There are two ways:
- An attribute and a property drawer. Mark a field with an attribute, and every Inspector draws that field with the toolbox control.
- A custom Editor. Build the whole Inspector of one component from toolbox controls.
The example scripts are in Assets/UIToolbox/Examples/InspectorFields (Jump, JumpPad, ToolboxCurveAttribute) and Assets/UIToolbox/Examples/Editor (ToolboxCurveDrawer, JumpPadEditor).
Try the example
- Click GameObject > 3D Object > Cube.
- In the Inspector, click Add Component and add Jump and Jump Pad.
- The Height of Jump is a toolbox
CurveField. Click the curve to open the curve editor. - Jump Pad shows a
Knob, aRangeSlider, aColorPickerswatch and aGradientField. Click the swatch or the gradient to open its editor. - Enter Play mode, right-click the header of Jump and click Play the jump.
Way 1: an attribute and a property drawer
The attribute goes in a runtime script, so a component can use it:
public class ToolboxCurveAttribute : PropertyAttribute { }
public class Jump : MonoBehaviour
{
[ToolboxCurve] public AnimationCurve height;
}
The drawer goes in an Editor folder or an editor assembly. CreatePropertyGUI returns the control, and BindProperty binds it to the field:
[CustomPropertyDrawer(typeof(ToolboxCurveAttribute))]
public class ToolboxCurveDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(
SerializedProperty property)
{
var field = new UIToolbox.CurveField(property.displayName);
field.AddToClassList(
BaseField<AnimationCurve>.alignedFieldUssClassName);
field.BindProperty(property);
return field;
}
}
- The
alignedFieldUssClassNameclass gives the label the width of the other labels of the Inspector. - A drawer for a type, such as
[CustomPropertyDrawer(typeof(AnimationCurve))], changes every curve field of the project. The attribute keeps the change to the fields that you mark. - The example attribute also takes a box for the keys:
[ToolboxCurve(0, 0, 1, 1)]setsCurveField.Range.
Way 2: a custom Editor
CreateInspectorGUI builds the Inspector. Each control names its field in bindingPath. The Inspector binds the returned element to the selected objects, so the controls need no BindProperty call:
[CustomEditor(typeof(JumpPad)), CanEditMultipleObjects]
public class JumpPadEditor : Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new Knob("Launch speed")
{
bindingPath = nameof(JumpPad.launchSpeed),
MaxValue = 30,
UseWheel = false,
});
return root;
}
}
- Set
UseWheel = falseon aKnob, so that the mouse wheel scrolls the Inspector. - Set
Compact = trueon aColorPicker: the row shows a swatch, and a click opens the full picker in a popup. SetEyedropper = false: the eyedropper reads the game screen, so it works only in Play mode. - A field that needs nothing more can stay a Unity field: add a
PropertyFieldfor it.
Which control for which field
| Field type | Toolbox controls |
|---|---|
float |
Knob, Rating, NumericUpDown |
double |
NumericUpDown |
int |
OptionSelector |
Vector2 |
RangeSlider (a low and a high value), XYPad (a point) |
Color |
ColorPicker |
Gradient |
GradientField |
AnimationCurve |
CurveField |
string |
ComboBox, SearchDropdown, CodeInput, KeyBindingField |
Values that Unity does not serialize
Unity does not serialize DateTime or TimeSpan, and the list value of a TagField does not bind to a serialized array. So DatePicker, TimePicker, TimeSpanPicker and TagField cannot bind to a field directly. Keep the value in a type that Unity serializes, and convert it in the drawer:
- A date: a
stringfield with[IsoDate], such as2026-09-24. The toolbox has a drawer for it. Alongof ticks works too. - A time or a duration: a
longof ticks, or afloatof seconds. - A list of tags: a
string[]or aList<string>.
In the drawer, set the control value from the property with SetValueWithoutNotify. In RegisterValueChangedCallback, write the converted value to the property and call serializedObject.ApplyModifiedProperties(), which records the undo. TrackPropertyValue on the control calls you back when the property changes elsewhere, such as after an undo.
Names that Unity has too
UnityEditor.UIElements has a CurveField and a GradientField of its own. In a file with using UnityEditor.UIElements;, write UIToolbox.CurveField, or add an alias such as using CurveField = UIToolbox.CurveField;.
Style sheets and popups
A toolbox control loads its style sheets when it attaches to a panel. In the editor, it also loads them on the editor window and on the Inspector, so the controls and their popups, such as the curve editor and the color picker, keep the toolbox look. See Sheet load order.
Next steps
- The controls on a runtime screen: Toolbox controls.
- The toolbox editors for text attributes in UI Builder: Build a screen in UI Builder.