Is there a method of "turning off" UI Documents or Visual Elements without resetting them?

Hi! I’m having an issue where I want to instantiate visual elements on a UI document through script when the game is started, but I don’t want them to evaporate when I close and reopen the menu. When I disable the UI Document behaviour, all of the stuff I instantiated in OnEnable() on another script goes away and doesn’t come back when I reenable it, of course. Is there a way to get the UI Document “out of the way” and invisible without actually disabling it, preserving the hierarchy changes I made through script? I’m open to hacky workarounds if need be.

I’ve also tried this by using SetEnabled() for the root visual elements of the documents I want to have persistent hierarchies, but this also seems to reset everything.

Starting in 2022.2, when switching from display:flex to display:none, the geometry of the objects will be kept and very little extra calculation are made when switching to display:flex again later and that it’s size has not changed

3 Likes