Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

VisualElement.GetComponentRefOrNullRef

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public ref T GetComponentRefOrNullRef();

Returns

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.

Description

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.

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.