Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Clone VIsualElement

Discussion in 'UI Toolkit' 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:
    1,231
    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.