View data persistence preserves the view data associated with visual elementsA node of a visual tree that instantiates or derives from the C# VisualElement
class. You can style the look, define the behaviour, and display it on screen as part of the UI. More info
See in Glossary in the UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary. View data refers to the state of the user interface that’s not part of the underlying data model of the UI. For example, view data could include the scroll position of a scroll bar or the selection of a list.
View data persistence addresses the issue of UI view data not persisting during certain events in the Editor:
Note: View data persistence only works in the Editor UI.
To enable view data persistence for the elements that support it, set the view data key to a unique string within the Editor window (the EditorWindow
type). You can set it in UI Builder, UXML, or C#:
view-data-key
attribute.viewDataKey
property.The following elements currently support view data persistence:
ScrollViewA UI Control which displays a large set of Controls in a viewable area that you can see by using a scrollbar. More info
See in Glossary
MultiColumnTreeView When you enable the view data persistence, those elements remember their internal view state:
For ScrollView, it remembers the scroll position.
For ListView, it remembers the selection.
For Foldout, it remembers the expanded state.
For TreeView, it remembers the selection.
For MultiColumnTreeView and MultiColumnListView, it remembers the selections and columns’ order, sorting and width.
To enable view data persistence for a read-only element, set the view data key on the parent element.
For example, a ScrollView has several read-only Scroller child elements. Each Scroller is given a view data key that’s unique within the ScrollView element. If you set a view data key for the Foldout, the Foldout has its view data persisted. Although Scrollers have keys, their view data isn’t persisted. You must set a view data key for their parent ScrollView to enable persistence. The Scrollers will combine their view data keys with the parent’s view data key to create a unique global view data key.
Note: Currently, the API necessary to add support for view data persistence is internal, which means you can’t enable view data persistence for your custom controls.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.