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

Create VisualTreeAsset from string at runtime?

Discussion in 'UI Toolkit' started by BackgroundMover, Jun 15, 2020.

  1. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    Is it possible to convert back and forth between text and visual tree asset at runtime?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This is not possible, at least not reliably. The conversion from VisualTreeAsset to a VisualElement tree via CloneTree() is not 1:1. More VisualElements are created than there are tags/items in the VisualTreeAsset. And many VisualElements have non-trivial constructors that can create (or destroy) more elements.

    If you add some info on your use case we can maybe offer some alternative supported workflows.