AssetDatabase.LoadAssetAtPath(aAbsolutePath)

First up, this is a great course on UI Builder.

In this course, the examples show this:
AssetDatabase.LoadAssetAtPath(“absolute/path/to/asset.uxml”)
Such as:
AssetDatabase.LoadAssetAtPath(“Assets/GameDev.tv Assets/TaskList/Edigor/EditorWindow/Window.uxml”)

Is there a way to use a relative path instead:
AssetDatabase.LoadAssetAtPath(“relative/path/to/asset.uxml”)
Such as:
AssetDatabase.LoadAssetAtPath("./Window.uxml")
or:
AssetDatabase.LoadAssetAtPath(“Window.uxml”)

Unfortunately, no, because LoadAssetAtPath is already utilizing a relative path in the first place (The Project Folder).
What you can do is put the files in a folder named Resources (though there are some limitations here).
Then, you can use

Resources.Load<VisualTreeAsset>("Window");

Note that you do not use the filename extension when loading the Resource, and there is a significant limitation in that you can’t have duplicate filenames… for instance, if you had a “Window.uxml” and a “Window.uss”, then Resources would fail to load it properly, you would need a different name for one of the two (For example I use the convention “WindowUXML.uxml” and “WindowUSS.uss” so when I do the Resources.Load, I can properly differentiate.

More on Resources

Privacy & Terms