This section describes the data type conversions and fields supported by PropertyField
.
Most built-in controls in UI Toolkit implement the INotifyValueChanged
interface for a specific data type. For example, DoubleField
implements INotifyValueChanged<Double>
, which means you can bind the DoubleField
control to a property of type double
. You can bind more data types with the binding system. For example, you can bind a property of type int
to a DoubleField
.
The following table lists the source and target data types that you can bind:
Source data type | Target data type of INotifyValueChanged |
---|---|
long |
|
int |
|
double |
|
float |
|
char |
|
Note: To prevent data loss, use a PropertyField
or use the appropriate data types as shown in the Fields supported by PropertyField table below.
PropertyField
When the 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 window is populated, if a custom Editor doesn’t exist for a type, the binding system calls InspectorElement.FillDefaultInspector()
. This creates a PropertyField
for each SerializedProperty
on the SerializedObject
.
Each PropertyField
has a matching control under it, such as an IntegerField
to represent an int
, or a Toggle
to represent a bool
. If the property has sub-properties, the PropertyField
has a Foldout
control. That Foldout
has the appropriate default controls under each sub-property. If you created a custom PropertyDrawer
for a Property, 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 returned from the PropertyDrawer
’s CreatePropertyGUI()
method is used instead.
Note:
When you create a custom UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary, don’t use a PropertyField
unless you can’t find a specific control for it. For example, to create a control in your visual tree and bind it to a Color
, use a ColorField
rather than a PropertyField
. This makes visual trees more lightweight and operations faster.
The use of PropertyField
incurs additional overhead because it resolves the concrete field to use after binding. This extra step can affect performance. However, PropertyField
is beneficial for some uses. For example, it supports custom drawers, which you can use to handle specific properties in a personalized way. This eliminates the need to guess the field type for drawing, which can reduce errors.
The following table lists fields supported by PropertyField
and their data type:
Field | Data type |
---|---|
BoundsField |
Bounds |
BoundsIntField |
BoundsInt |
ColorField |
Color |
CurveField |
AnimationCurve |
FloatField |
float |
GradientField |
Gradient |
Hash128Field |
Hash128 |
IntegerField |
int |
IntegerField |
int, for the ArraySize |
LayerMaskField |
unit |
LongField |
long |
ObjectField |
UnityEngine.Object |
PopupField <string> |
Enum |
RectField |
Rect |
RectIntField |
RectInt |
TextField |
string |
TextField , with a maxLength=1 |
char |
Toggle |
bool |
Vector2Field |
Vector2 |
Vector2IntField |
Vector2Int |
Vector3Field |
Vector3 |
Vector3IntField |
Vector3Int |
Vector4Field |
Vector4 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.