(2019.1) UIElements Migration Guide
(2019.1) UIElements Migration Guide
This document aims at helping you in the process of migrating / validating the use of the API.
It is not exhaustive and focuses on the most likely breakage you might encounter.
You can always get in touch with us if you don’t know how to replace an old API call or for any
other migration issue.
Namespace changes
The OnStylesResolved() virtual function was removed and replaced with the
CustomStyleResolvedEvent event.
The dataWatch property was removed. This feature will not be available anymore. One can
use SerializedProperty bindings instead.
The focusIndex property was removed. It’s no longer necessary to specify an index for an
element to be focusable, setting element.focusable=true is sufficient. focusIndex was
renamed to tabIndex.
The INotifyValueChanged interface does not contain method for registering callbacks
anymore. Those were moved to extension methods.
The OnValueChanged() method was renamed RegisterValueChangedCallback().
The RemoveValueChanged() method was renamed
UnregisterValueChangedCallback().
The VisualElement.styles property was previously reflecting both inline styles added via
the C# and resolved styles coming from style sheets. The VisualElement.style object now
only reflects properties defined in C#. The resolvedStyles property must be used to query
actual values coming from both style sheets and C#.
Persistence changes
Elements in the physical hierarchy of another element will only persist their view data if their
physical root has viewDataKey defined.
Most built-in controls were refactored in order to include a label when necessary in the
hierarchy. This means the hierarchy of a field is now comprising a container, a label (present or
not depending on the value of the label attribute) and the field itself (the inner input).
ColorField TextField
CurveField DoubleField
GradientField FloatField
ObjectField IntegerField
Toggle LongField
MinMaxSlider BoundsField
Slider BoundsIntField
SliderInt RectField
RectIntField
EnumField Vector2Field
MaskField Vector2IntField
PopupField Vector3Field
LayerMaskField Vector3IntField
LayerField Vector4Field
TagField
Currently, the way to register a callback on inner inputs is by using UQuery. Here is an example
of setting a KeyDownEvent callback on a textfield, using UQuery and the inner element class
name :
This mechanism can be extended to all other callbacks needing information directly from the
inner part of the field.
As for styling, the following class structure is now available to correctly style those fields :
Label unity-base-field__label
When the field label has a dragger, the label also has unity-base-field__label--with-dragger
(for DoubleField, FloatField, IntegerField,
LongField)
In addition of the above uss class, the following elements can be styled using the following uss
class. The old style values are provided at the end of document in an annex to help figuring out
differences in style.
CurveField unity-curve-field
unity-curve-field__content
unity-curve-field__border
GradientField unity-gradient-field
unity-gradient-field__border
ObjectField unity-object-field-display
unity-object-field-display__icon
unity-object-field-display__label
unity-object-field-display--accept-drop
Toggle unity-toggle
unity-toggle--no-text
unity-toggle__checkmark
unity-toggle__text
MinMaxSlider unity-min-max-slider
unity-min-max-slider__tracker
unity-min-max-slider__dragger
unity-min-max-slider__min-thumb
unity-min-max-slider__max-thumb
EnumField unity-enum-field
unity-enum-field__text
unity-bounds-int-field
unity-bounds-int-field__position-field
unity-bounds-int-field__size-field
Other controls
For the following classes, the structure is identical but class lists can now be used to assign
styles to them. The default USS files from the editor use those selectors.
Label unity-text-element
unity-label
Button unity-text-element
unity-button
IMGUIContainer unity-imgui-container
text-alignment -unity-text-align
(CurveField class)
curve-color --unity-curve-color
(TextField class)
selection-color --unity-selection-color
cursor-color --unity-cursor-color
(Image class)
image --unity-image
image-size --unity-image-size
(ListView class)
item-height --unity-item-height
We now assign USS classes to all elements. Those classes follow the BEM methodology
(http://getbem.com/). We updated the selectors in the default USS files to use these class
names instead the element type name (Label, Button) or element name (#Checkmark). This
change may impact your styling, as the new default USS rules have different, generally higher,
specificity than the previous ones.
We are planning to release the full list of available classes names. Until then you can look at the
static string constants exposed by controls, for example DoubleField.ussClassName.
UXML changes
If you specify namespaces in your UXML files, you will need to update them to the use
non-experimental ones.
The UXML slots feature was disabled until further design review.
GraphView changes
The GraphView namespace has moved from
UnityEditor.Experimental.UIElements.GraphView to
UnityEditor.Experimental.GraphView.
Since GraphElement inherits from VisualElement, all the changes listed in the first section
apply.
GraphView custom style properties were prefixed according to the new rule.
edge-width --edge-width
selected-edge-color --selected-edge-color
ghost-edge-color --ghost-edge-color
segment-size --segment-size
segment-color --segment-color
delete-segment-color --delete-segment-color
layer --layer
spacing --spacing
thick-lines --thick-lines
line-color --line-color
thick-line-color --thick-line-color
grid-background-color --grid-background-color
distance --distance
port-color --port-color
disabled-port-color --disabled-port-color
separator-height --separator-height
separator-extent --separator-extent
animation-duration --animation-duration
ColorField ColorField {
min-height: 18;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
}
CurveField CurveField {
min-height: 18;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
background-color:
rgb(86,86,86);
curve-color: #00ff00;
}
GradientField GradientField {
min-height: 18;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
}
ObjectField ObjectField {
min-height: 16;
flex-direction: row;
margin-left: 4;
margin-top: 4;
margin-right: 4;
margin-bottom: 4;
}
ObjectField > ObjectFieldDisplay {
height: 16;
flex-direction: row;
flex: 1 0 0;
margin-left: 0;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
-unity-slice-left: 4;
-unity-slice-top: 4;
-unity-slice-right: 4;
-unity-slice-bottom: 4;
}
Toggle Toggle {
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
padding-top: -1;
padding-bottom: 2;
padding-left: 3;
padding-right: 3;
flex-direction: row;
}
Toggle > #Checkmark {
padding-top: 0;
width:16;
height:15;
flex:0 0 auto;
align-self:Center;
-unity-slice-top: 15;
-unity-slice-left: 16;
}
MinMaxSlider MinMaxSlider {
height: 18;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
}
MinMaxSlider .thumbelement {
cursor: resize-horizontal;
position:absolute;
}
/* Horizontal slider */
SliderInt.horizontal, Slider.horizontal {
height: 18;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
}
EnumField EnumField {
-unity-text-align: middle-left;
height: 16;
font-size: 9;
margin-left: 4;
margin-top: 3;
margin-right: 8;
margin-bottom: 3;
padding-left: 6;
padding-top: 0;
padding-right: 6;
padding-bottom: 3;
-unity-slice-left: 6;
-unity-slice-top: 4;
-unity-slice-right: 14;
-unity-slice-bottom: 4;
}
MaskField .popupField {
PopupField -unity-text-align: middle-left;
LayerField height: 16;
TagField font-size: 9;
LayerMaskField margin-left: 4;
margin-top: 3;
margin-right: 8;
margin-bottom: 3;
padding-left: 6;
padding-top: 0;
padding-right: 6;
padding-bottom: 3;
-unity-slice-left: 6;
-unity-slice-top: 4;
-unity-slice-right: 14;
-unity-slice-bottom: 4;
}
RectField .compositeField {
RectIntField flex-direction: row;
Vector2Field flex-wrap: Wrap;
Vector2IntField }
Vector3Field
Vector3IntField .compositeField > .field {
Vector4Field flex-direction: row;
height: 20;
flex: 1 1 140;
}
Label Label {
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
padding-left: 2;
padding-top: 1;
padding-right: 2;
padding-bottom: 2;
overflow: hidden;
}
Button Button {
-unity-text-align: middle-center;
border-left-width: 6;
border-top-width: 4;
border-right-width: 6;
border-bottom-width: 4;
margin-left: 4;
margin-top: 3;
margin-right: 4;
margin-bottom: 3;
padding-left: 6;
padding-top: 2;
padding-right: 6;
padding-bottom: 3;
-unity-slice-left: 6;
-unity-slice-top: 4;
-unity-slice-right: 6;
-unity-slice-bottom: 4;
}