ManagedReferenceField Class

Description

Element that handles fields with the SerializeReference attribute.

public class ManagedReferenceField : VisualElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle
Inheritance
Remarks

This element contains a PropertyField and rebinds it when the field's reference changes type. It also sends a ReferenceTypeChangeEvent when that happens.

Unity 2022 adds support for Managed References in UI Toolkit, but it's currently a bit buggy in some edge cases (for example, it doesn't like when two classes contain fields with the same name but different type). Use this element in 2022 if you need to go around those bugs or to take advantage of the ReferenceTypeChangeEvent.

Examples

A basic example. See ArrayPropertyField for how to use it with reorderable lists.

class ACustomEditor : Editor
{
    public override VisualElement CreateInspectorGUI()
    {
        var root = new VisualElement();
        // "managed" would be a field with the [SerializeReference] attribute.
        SerializedProperty managedProp = serializedObject.FindProperty("managed");
        root.Add(new ManagedReferenceField(managedProp));
        return root;
    }
}

Constructors

ManagedReferenceField(SerializedProperty)

Constructor. Receives a SerializedProperty for a field that has the SerializeReference attribute. It still needs to be bound to work properly.

ManagedReferenceField(SerializedProperty, String)

Constructor. Receives a SerializedProperty for a field that has the SerializeReference attribute. It still needs to be Bound to work properly.

Fields

propertyFieldUssClassName

USS class name for the PropertyField inside.

trackerUssClassName

USS class name for the ManagedReferenceTypeTracker inside.

ussClassName

USS class name of elements of this type.

Properties

periodicalUpdateInterval

In addition to checking the reference's type when things change in the editor, there's a periodical check to catch changes made from runtime. By default it's done around every five seconds, but the interval can be changed through this property.

Extension Methods

UIToolkitExtensions.GetLocalRect(VisualElement)
UIToolkitExtensions.GetChildren<TElement>(VisualElement, List<TElement>, Func<TElement, Boolean>)
UIToolkitExtensions.GetFirstChild<TElement>(VisualElement, Func<TElement, Boolean>)
UIToolkitExtensions.ForEachChild<TElement>(VisualElement, Action<TElement>)