Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetComponentRefOrNullRef<T>()

Returns 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.
Read time 1 minuteLast updated 6 days ago

Definition

public ref T GetComponentRefOrNullRef<T>() where T : struct, IVisualElementComponent

Returns

Type

Description

TA reference to the live component data, or a null reference when the component is not attached. A valid reference stays valid until a component is added to or removed from this element.

Remarks

Always check the returned reference with
System.Runtime.CompilerServices.Unsafe.IsNullRef
before using it. Reading or writing through a null reference throws NullReferenceException. When the component is attached, this method behaves exactly like VisualElement.GetComponent.