Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


UxmlTypeReferenceAttribute

Provides information about the expected type when applied to a Type field or property that has the UxmlAttributeAttribute attribute.
Read time 4 minutesLast updated 6 days ago

Definition

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]public class UxmlTypeReferenceAttribute : PropertyAttribute

Remarks

When defining a Type field or property with the UxmlAttributeAttribute in Unity, you can use the UxmlTypeReference attribute to specify the base type that the value should inherit from. This allows you to provide additional information about the expected type of the value and helps Unity ensure that the correct type is assigned to the attribute.
The following example creates a custom control and restricts the attribute type to only accept values that are derived from VisualElement:

Examples

using System;using UnityEngine.UIElements;[UxmlElement]public partial class TypeRestrictionExample : VisualElement{ [UxmlAttribute, UxmlTypeReference(typeof(VisualElement))] public Type elementType { get; set; }}

Fields

Value

Description

baseTypeThe base type that the value inherits from.

Constructors

Constructor

Description

UxmlTypeReferenceAttribute()Provides information about the expected type when applied to a Type field or property that has the UxmlAttributeAttribute attribute.
UxmlTypeReferenceAttribute(System.Type)Provides information about the expected type when applied to a Type field or property that has the UxmlAttributeAttribute attribute.

Inheritance

Inherited Members