Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

VisualElement.Hierarchy.Clear

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 void Clear();

Description

Removes all child elements from this element's VisualElement.contentContainer.

Only the child elements are removed, not the element itself. Only the immediate children are removed. To remove all descendants, use the VisualElement.Hierarchy.Clear overload with the VisualElementClearOptions.Recursive flag.


Declaration

public void Clear(VisualElementClearOptions options);

Parameters

Parameter Description
options Allows which actions are performed when clearing the children.

Description

Removes all child elements from this element's VisualElement.contentContainer, using the specified options. Use this method to reduce memory usage.

Only the child elements are removed, not the element itself.

Using default options, only the immediate children are removed and no additional action is performed.

To remove all descendants from their parent, specify the VisualElementClearOptions.Recursive flag.

To invoke the VisualElement.ReleaseResources method on all descendants, specify the VisualElementClearOptions.RecursiveReleaseResources flag. This flag implies that the hierarchy is cleared recursively, because an element must have no children when it is released.

You can use the combination of these flags to clear a large number of elements from the hierarchy and immediately release resources to reduce memory usage. For more information, refer to VisualElement.ReleaseResources. It also removes internal parent and child relationships between elements, which can help with garbage collection speed and troubleshooting memory leaks.