Default InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary is a standard way to display serialized object properties without any custom modifications. When you use FillDefaultInspector method of the InspectorElement class, it automatically creates the default hierarchy with the default property fields.
This example extend the CreateInspectorGUI()
method in the Create a Custom Inspector example to create a default Inspector for the Car
component. The example creates a Foldout
control in the Car_Inspector_UXML.uxml
file and attaches the default Inspector UI to it.
This guide is for developers familiar with the Unity Editor, UI Toolkit, and C# scripting. Before you start, get familiar with the following:
Create a Foldout control to display the default Inspector UI.
Double-click the Car_Inspector_UXML.uxml
file to open it in UI Builder.
Add a Foldout control to your UI, name it Default_Inspector
, and set a label text:
To attach the default Inspector UI to the Foldout, you must obtain a reference to it. You can retrieve the visual elementA node of a visual tree that instantiates or derives from the C# VisualElement
class. You can style the look, define the behaviour, and display it on screen as part of the UI. More info
See in Glossary of the Foldout from the visual treeAn object graph, made of lightweight nodes, that holds all the elements in a window or panel. It defines every UI you build with the UI Toolkit.
See in Glossary of your Inspector using UQuery, and use the FillDefaultInspector method of the InspectorElement class to attach the default Inspector UI to the Foldout control.
In the Car_Inspector.cs
file, update the CreateInspectorGUI()
method to get a reference to the Default_Inspector
Foldout and attach the default Inspector UI to it:
public override VisualElement CreateInspectorGUI()
{
...
// Get a reference to the default Inspector Foldout control.
VisualElement InspectorFoldout = myInspector.Q("Default_Inspector");
// Attach a default Inspector to the Foldout.
InspectorElement.FillDefaultInspector(InspectorFoldout, serializedObject, this);
// Return the finished Inspector UI.
return myInspector;
}
Select the GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary that has the Car
component to it. The Inspector for the car
component now displays the Default Inspector
Foldout with the default Inspector UI inside.