Is there a way to duplicate or clone a Visual Element including its hierarchy? Since Visual Element is a class, it is passed by reference, which makes it impossible to add a Visual Element to multiple places without breaking things. Being able to duplicate the Visual element and its hierarchy would fix this.
//This is how it could look:
var original = new VisualElement();
var clone = original.Clone();
//Or something like this:
var clone = Instantiate(original);
Hmmm, that solution is unfortunately not possible in my case. All of the UI is procedurally generated based on a GameObject hierarchy, meaning that I use neither USS nor UXML. But I will see if I can find a workaround. Currently, I can just return the output as a completely new Visual Element, which works good enough. This is similar to the solutions mentioned further down in the thread.