Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Create VisualTreeAsset from string at runtime?

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

  1. vestigial

    vestigial

    Joined:
    May 9, 2015
    Posts:
    174
    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:
    945
    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.
     
unityunity