Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Load UI Toolkit uxml at runtime

Discussion in 'UI Toolkit' started by Sergey_ksubox, Sep 4, 2021.

  1. Sergey_ksubox

    Sergey_ksubox

    Joined:
    Jul 29, 2015
    Posts:
    26
    Hello,
    Need some hints how to load/instantiate UXML dialog at runtime.
    I have UXML document, using USS stylesheet with background sprite.
    I put UXML & USS in same Resource folder and can load UXML, but it looks weird, like no USS and sprite loaded.
    Code (CSharp):
    1. var uiAsset = Resources.Load<UnityEngine.UIElements.VisualTreeAsset>("RightClickMenu/AddDelMenu");
    2. m_aUIDoc.visualTreeAsset = uiAsset;
    Do we have any reasonable way for easy UXML/CSS/Sprites load at runtime ?
     
  2. Sergey_ksubox

    Sergey_ksubox

    Joined:
    Jul 29, 2015
    Posts:
    26
    Actually I solved issue by moving spritre to the same Resource folder and resaving dialog in UI builder.