Search Unity

Create a VisualElement with builder, but instantiate it from code

Discussion in 'UI Toolkit' started by rogerdv, Nov 10, 2019.

  1. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Im working in a very complex dialog editor for my RPG. Each dialog node could contain several checks for conditions, text/audio references in different languages, and any other that can come up uin the future. Is there some way I can use UI builder to create the element containing the node data, but save it separated from the main hierarchy and instantiate it from code?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Yep. The UI Builder generates UXML files. You can load these files in C# anywhere you want, or reuse them inside other UXML files. Just create your dialog UI in its own UXML file and instantiate it in code via CloneTree().