Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


VisualElement

Base class for objects that are part of the UIElements visual tree.
Read time 10 minutesLast updated 2 days ago

Definition

[UxmlElement(libraryPath = "Containers")][Icon("UIToolkit/Icons/VisualElement.png")]public class VisualElement : Focusable, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle

Remarks

VisualElement contains several features that are common to all controls in UIElements, such as layout, styling and event handling. Several other classes derive from it to implement custom rendering and define behaviour for controls.
To inherit from VisualElement and create a custom control, refer to Creating a custom control.

Static Fields

Value

Description

disabledUssClassNameUSS class name of local disabled elements.

Constructors

Constructor

Description

VisualElement()Initializes and returns an instance of VisualElement.

Properties

Property

Description

childCountNumber of child elements in this object's contentContainer.
contentContainerLogical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.
contentRectThe rectangle of the content area of the element, in the local space of the element. (Read Only)
customStyleThe custom style properties accessor of a VisualElement (Read Only).
dataSourceAssigns a data source to this VisualElement which overrides any inherited data source. This data source is inherited by all children.
dataSourcePathPath from the data source to the value.
dataSourceTypeThe possible type of data source assignable to this VisualElement.
disablePlayModeTintPlay-mode tint is applied by default unless this is set to true. It's applied hierarchically to this VisualElement and to all its children that exist on an editor panel.
enabledInHierarchyReturns true if the VisualElement is enabled in its own hierarchy.
enabledSelfReturns true if the VisualElement is enabled locally.
experimentalReturns the UIElements experimental interfaces.
generateVisualContentDelegate function to generate the visual content of a visual element.
hasActivePseudoStateReturns true if this element matches the
:active
pseudo-class.
hasCheckedPseudoStateReturns true if this element matches the
:checked
pseudo-class.
hasDisabledPseudoStateReturns true if this element matches the
:disabled
pseudo-class.
hasEnabledPseudoStateReturns true if this element matches the
:enabled
pseudo-class.
hasFocusPseudoStateReturns true if this element matches the
:focus
pseudo-class.
hasHoverPseudoStateReturns true if this element matches the
:hover
pseudo-class.
hasInactivePseudoStateReturns true if this element matches the
:inactive
pseudo-class.
hasRootPseudoStateReturns true if this element matches the
:root
pseudo-class.
hierarchyAccess to this element physical hierarchy
this[]Retrieves the child element at a specific index.
languageDirectionIndicates the directionality of the element's text. The value will propagate to the element's children.
layoutThe position and size of the VisualElement relative to its parent, as computed by the layout system. (Read Only)
localBoundReturns a Rect representing the Axis-aligned Bounding Box (AABB) after applying the transform, but before applying the layout translation.
nameThe name of this VisualElement.
paddingRectThe rectangle of the padding area of the element, in the local space of the element.
panelThe panel onto which this VisualElement is attached.
parentThe parent of this VisualElement.
pickingModeDetermines if this element can be the target of pointer events or picked by IPanel.Pick queries.
resolvedStyleThe final rendered style values of a visual element, as it's rendered in the current frame.(Read Only)
resourcesReleasedIndicates if the element has released its reusable resources, in which case it can not be modified or added again.
scaledPixelsPerPointReturn the resulting scaling from the panel that considers the screen DPI and the customizable scaling factor, but not the transform scale of the element and its ancestors. See _scaledPixelsPerPoint. This should only be called on elements that are part of a panel.
scheduleRetrieves the IVisualElementScheduler associated to this VisualElement. Use it to enqueue actions.
styleSets the style values on a VisualElement.
styleSheetsReturns a VisualElementStyleSheetSet that manipulates style sheets attached to this element.
tooltipText to display inside an information box after the user hovers the element for a small amount of time. This is only supported in the Editor UI.
usageHintsA combination of hint values that specify high-level intended usage patterns for the VisualElement. This property can only be set when the VisualElement is not yet part of a Panel. Once part of a Panel, this property becomes effectively read-only, and attempts to change it will throw an exception. The specification of proper UsageHints drives the system to make better decisions on how to process or accelerate certain operations based on the anticipated usage pattern. Note that those hints do not affect behavioral or visual results, but only affect the overall performance of the panel and the elements within. It's advised to always consider specifying the proper UsageHints, but keep in mind that some UsageHints might be internally ignored under certain conditions (e.g. due to hardware limitations on the target platform).
userDataThis property can be used to associate application-specific user data with this VisualElement.
viewDataKeyUsed for view data persistence, such as tree expanded states, scroll position, or zoom level.
visibleIndicates whether or not this element should be rendered.
visualTreeAssetSourceStores the asset reference, if the generated element is cloned from a VisualTreeAsset.
worldBoundReturns the axis-aligned bounding box of the element in panel coordinates after the cumulative transform from the IPanel root.
worldTransformReturns a matrix that cumulates the following transformations (in order):

Methods

Method

Description

AddAdds an element to the contentContainer of this element.
AddComponentAttaches a component of type
T
to this element.
AddMeshModifierRegisters a modifier that runs after this element's mesh generation completes, before its vertex data is copied to the GPU.
AddToClassListAdds multiple classes to the class list of the element in order to assign styles from USS. Note the class names are case-sensitive.
BringToFrontBrings this element to the end of its parent children list. The element will be visually in front of any overlapping sibling elements.
ChildrenReturns the elements from its contentContainer.
ClassListContainsSearches for a class in the class list of this element.
ClearRemoves all child elements from this element's _contentContainer.
ClearBindingRemoves a binding from the element.
ClearBindingsRemoves all bindings from the element.
ClearClassListRemoves all classes from the class list of this element. VisualElement.AddToClassList
ClearMeshModifiersRemoves every modifier previously registered on this element. No-op if none are registered.
ContainsChecks if this element is an ancestor of the specified child element.
ContainsPointChecks if the specified point intersects with this VisualElement's layout.
ElementAtRetrieves the child element at a specific index.
EnableInClassListEnables or disables the class with the given name.
FindAncestorUserDataSearches up the hierarchy of this VisualElement and retrieves stored userData, if any is found.
FindCommonAncestorFinds the lowest common ancestor between two VisualElements inside the VisualTree hierarchy.
GetBindingGets the binding instance for the provided targeted property.
GetBindingInfosGets information on all the bindings of the current element.
GetClassesRetrieve the classes for this element.
GetClassNamesRetrieve the classes for this element.
GetComponentReturns a reference to the attached component of type
T
.
GetComponentRefOrNullRefReturns a reference to the component of type
T
attached to this element, or a null reference when the component is not attached. This method never adds a component.
GetDataSourceContextQueries the _dataSource and _dataSourcePath of a binding object.
GetFirstAncestorOfTypeWalks up the hierarchy, starting from this element's parent, and returns the first VisualElement of this type
GetFirstOfTypeWalks up the hierarchy, starting from this element, and returns the first VisualElement of this type
GetHierarchicalDataSourceContextQueries the _dataSource and _dataSourcePath inherited from the hierarchy.
GetOrAddComponentReturns a reference to the component of type
T
attached to this element. If the component is not attached yet, it is added first.
HasBindingAllows to know if a target property has a binding associated to it.
HasComponentChecks whether a component of type
T
is attached to this element.
IndexOfRetrieves the child index of the specified VisualElement.
InsertInsert an element into this element's contentContainer
IsMarkedForRepaintChecks if the VisualElement is marked dirty for repaint.
MarkComponentDirtyMarks the attached component of type
T
as changed, so that its
[OnComponentChanged]
handler runs once during the next update.
MarkDirtyRepaintMarks that the VisualElement requires a repaint.
MarkDirtyStylesMarks the element's resolved styles dirty so the next update re-resolves them, re-reading USS custom property values. The style counterpart of VisualElement.MarkDirtyRepaint.
NotifyComponentChangedNotifies the data binding system that a field of an attached component changed, so a binding targeting that field (for example
${component:Tooltip}.text
) can publish the new value.
PlaceBehindPlaces this element right before the sibling element in their parent children list. If the element and the sibling position overlap, the element will be visually behind of its sibling.
PlaceInFrontPlaces this element right after the sibling element in their parent children list. If the element and the sibling position overlap, the element will be visually in front of its sibling.
ReleaseResourcesReleases reusable resources associated with this element and makes the element unusable.
RemoveRemoves this child from the _hierarchy of its _contentContainer.
RemoveAtRemoves a child, at the provided index, from the list of children of the current element.
RemoveComponentRemoves the attached component of type
T
.
RemoveFromClassListRemoves a class from the class list of the element.
RemoveFromHierarchyRemoves this element from its parent hierarchy.
RemoveMeshModifierRemoves a previously-registered modifier. The registration is identified by delegate equality; pass the same callback reference that was registered. No-op if the callback is not registered. If the callback was registered more than once, only the first matching registration is removed.
SendEventSends an event to the event handler.
SendToBackSends this element to the beginning of its parent children list. The element will be visually behind any overlapping sibling elements.
SetActivePseudoStateSets whether or not this element is displayed as being active.
SetBindingAssigns a binding between a target and a source.
SetCheckedPseudoStateSets whether or not this element is displayed as being checked.
SetEnabledChanges the VisualElement enabled state. A disabled visual element does not receive most events.
SortReorders child elements from this VisualElement contentContainer.
ToggleInClassListToggles between adding and removing the given class name from the class list.
TryGetBindingGets the binding instance for the provided targeted property.
TryGetDataSourceContextQueries the _dataSource and _dataSourcePath of a binding object.
TryGetLastBindingToSourceResultReturns the last BindingResult of a binding object from the UI to the data source.
TryGetLastBindingToUIResultReturns the last BindingResult of a binding object from the data source to the UI.
TryRemoveComponentRemoves the attached component of type
T
, if one is attached.

Structs

Struct

Description

VisualElement.HierarchyHierarchy is a struct allowing access to the hierarchy of visual elements

Enums

Enum

Description

VisualElement.MeasureModeThe modes available to measure VisualElement sizes.

Inheritance