In a UXML file, you can use the <Template>
and the <Style>
elements to reference other UXML or USS files. The two elements both accept either an src
attribute or a path
attribute.
src
attributeUse the following syntax for the src attribute:
src="<path-to-file>/<file-name-with-extension>"
Any errors during import, such as missing files, trigger an error message.
You can use a relative or an absolute path:
Assets
folder and begin with a /
or project://database/
. For example, /Assets/myFolder/myFile.uss
or project://database/Assets/myFolder/myFile.uss
./
. For example, ../myFolder/myFile.uss
.Note: To reference a file from packages, use the absolute path of the package file that starts from the Packages
folder. For example, /Packages/com.unity.package.name/file-name.uss
or project://database/Packages/com.unity.package.name/file-name.uss
. you must use the format of com.unity.package.name
rather than package name
for the package name.
path
attributeThe path
attribute uses the Unity Resources mechanisms, but doesn’t offer error reporting at import time and doesn’t allow relative paths.
The path
attribute accepts files located in either the Resources
folder or the Editor Default Resources
folder, with the following rules:
Resources
folder, don’t include the file extension. For example, write path="template"
for a file located at Assets/Resources/template.uxml
.Editor Default Resources
folder, you must include the file extension. For example, write path="template.uxml"
for a file located at Assets/Editor Default Resources/template.uxml
.