An object field is an input field that is used when a user needs to assign an object or asset to a subject.
In addition to using the Object Field Button to assign objects, users can drag and drop objects to the object field body.
When an object is being dragged on an object field, it’s entire body will be highlighted in blue.
Use allowSceneObjects to allow scene objects to be assigned to the object field.
Users can set up the object parameter to be a Project Asset and set the type of object to be any type of asset.
Change GameObject parameter in obj, typeof(GameObject) to define different object types.
Ensure that the allowSceneObjects parameter is false if the object reference is stored as part of an asset, since assets can't store references to objects in a Scene.
Users can assign an object to the object field by;
Clicking the object field body will highlight the assigned objects and their path in the Project panel.
A numeric field can contain and be paired with the following elements:
1. Control label
2. Object icon
3. Object label
4. Object field button
5. Body (container)
Labels should be placed to the left of the object field and be should be simple and clear, relating to the nature of content.
Icon representing the type of object picked.
Label of the picked object.
Button to open up the picker modal.
The body of the object field is the container where content (Icons, Object Icon and Label, Object Field Button) is displayed.
Default state of an Object Field.
When hovering over an object field body the border will be highlighted.
When hovering over the object field button, both the button and border will be highlighted.
When an object field enters the Focused state its label and border will be highlighted in blue.
When an object is being dragged on an object field, it’s entire body will be highlighted in blue.
An object field that is disabled will indicate so by having its body “greyed out” and will not accept inputs or react to hovering.
Go to Window > UI Toolkit > Samples, to view code samples in C# / USS / UXML.
UI Toolkit
Unity - Scripting API:
ObjectField
IMGUI
Unity - Scripting API:
EditorGUI.ObjectField