Search Unity

UIElements View

Discussion in 'UIElements' started by FaizanDurrany, Jul 31, 2018.

  1. FaizanDurrany

    FaizanDurrany

    Joined:
    Dec 25, 2014
    Posts:
    24
    Don't know if this is the correct place to post this, cannot find a forum specifically for UIElements.

    How do I "load" the custom UXML View into an editor window?
    Cannot find anything about the UIElements Views in the documentation
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    44
    The editor window has a root VisualElement. You need to load the UXML file and clone its asset into it:

    Code (CSharp):
    1.    public class MyWindow: EditorWindow
    2.     {
    3.         void OnEnable()
    4.         {
    5.             var asset = Resources.Load("myUxmlFileWithoutExtension") as VisualTreeAsset;
    6.             var root = this.rootVisualElement;
    7.             root.Add(asset.CloneTree(null));
    8.         }
    9.     }
     
  3. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    96
    FYI, we now have a dedicated sub-forums where you can use for all your questions and feedback related to UI Systems Previews.

    Cheers,