We’ve talked about this before on the forums, but I’d like to give it another go!
There’s a lot of ways to get several identical copies of VisualElements - instantiating the same VisualTreeAsset a bunch, creating a custom type with a factory, etc. But those all come with a lot of formalities and work.
There’s a lot of instances where it’d be nice to just take a VisualElement in our hierarchy, Clone() it a bunch of times, and then be done with it.
Are there any plans to support that? What kind of obstacles are in the way of that happening?
I’m tempted to quote myself from the thread you linked :), but I’ll try a new wording.
I think it comes down to this:
I think the formalities would actually end up being “more” for clonable VisualElements than the alternatives you mentioned. VisualElements have non-trivial constructors which often build more VisualElements that should not be cloned. They also have references to other non-uniquely-identifiable elements and objects (ie. event callbacks). It’s not impossible to replicate all this, but it would require a lot of restrictions and explicit handling/markup (by user code) to make it possible. I think you’d end up with more scaffolding than just going with UXML.
But happy to discuss further if you have specific new use case examples where you’d wish to use cloning.