Search Unity

Clone VIsualElement

Discussion in 'UIElements' started by Devi-User, Nov 20, 2018.

  1. Devi-User

    Devi-User

    Joined:
    Apr 30, 2016
    Posts:
    61
    I would like to receive a new element, using already existing. Is there a way to clone them?
    Or is it better to do it through templates?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    226
    UXML templates are your friend here. That is the recommend way to "instance" elements.

    It's not easier nor harder to clone a VisualElement hierarchy than it is to clone the GameObject transform hierarchy. Both are C# objects with arbitrary data on them and a healthy amount of virtualization. You could in theory do it with a lot of reflection but I wouldn't recommend it.