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
- Type: Method
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
public ref T GetComponentRefOrNullRef<T>() where T : struct, IVisualElementComponent
Returns
Type | Description |
|---|---|
| T | A 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 before using it. Reading or writing through a null reference throws NullReferenceException. When the component is attached, this method behaves exactly like VisualElement.GetComponent.
System.Runtime.CompilerServices.Unsafe.IsNullRef