This might be a dumb question, but I’m about to start with UI Toolkit, and I’m adding it to a package, not a project. So I create a new Editor Window, which creates the three files (.cs, .uss and .uxml), and following the tutorial I want to link the USS to my window, which results in “Asset at path {cut-off path} is not a StyleSheet”.
Creating a new USS results in “Could not find a part of the path {cut-off path}” in the console. It seems to me that your tooling is not set up for supporting package-level UI. Is there a workaround or something I’m missing?
I played around some more, and when you create a new UXML through the editor, the generated .cs actually loads the style sheet via code. Here, the package file path works. So I’m not sure what the UI Builder is supposed to do actually when you add style sheets there.
I am assuming you are doing an editor window but I could be wrong, please let me know if this is the case.
I started testing in 2022.2, and I think someone changed the default example when you do a right click->create->UI toolkit ->editor window.
I think you need an asmdef for editor assemblies in the package (instead of just a folder called editor). Don’t quote me on this, but I have the reflex of creating one anyway before creating the window.
The resulting CreateGUI() does not refer to the style anymore,
And the style from the uss is applied to the third label:
So, if I understood your problem correctly, it is not reproducible in 2022.2a8 so far. I didn’t have 2021.2.14 installed so I figured I should start with something I already had on hands.
I will do another pass with the builder later on today if everything goes well.
Can you post the resulting style tag from the uxml you are having issues with? Like this one: <Style src="project://database/Packages/com.test.mypackage/editor/usstest.uss?fileID=7433441132597879392&guid=6f4f2b74561dd414ebd820524047ee96&type=3#usstest" />
FYI the first part is the asset path that is used by default, and we fall back to the GUI if the asset was moved.
I had a similar problem where I was developing an asset library and then using it as a package within another project. I just check to see if the package’s virtual path is valid using AssetDatabase API and if it is I simply switch the base path. See example below.
Add this script into an Editor folder:
public static class AssetPaths
{
public static string packageRootDir
{
get
{
// regular assets path
string rootDir = "Assets/whatever/";
// IMPORTANT: this is linked to the "name" property of the package manifest json file
string packagesDir = "Packages/com.whatever/";
if (AssetDatabase.IsValidFolder(packagesDir))
rootDir = packagesDir;
return rootDir;
}
}
}
This Bug is over a year old and still not fixed…
It is really annoying that you cannot use stylesheet files with the ui builder when working in a package…
I would like to +1 this issue, in our project we are building a framework of packages where each package features its own UI assets; but currently we cannot bring it together in the project due to this issue
@mvriel Have you tried my suggestion above? I am able to use the UI Builder to design Editor UI in a package and I can import it just fine in other projects.
For some reason, I never got a notification about this… we have since abandoned UI Toolkit because of these issues but I do not recall whether I tried your solution or if there was another issue… I might do a POC with this and see if it could work; but that won’t be soon
I wonder what people were doing where they couldn’t get it to work.
I’ve been using UI Toolkit for numerous editor tools that I integrated into other projects via the Unity Package Manager and have zero issues doing so. No real workarounds required either.
Well, for one: trying to use it in an application and not in an editor. And the problem for us was referencing a USS or template from a package in another. We were trying to create a UI Kit as a package that could be used by consuming packages; but -when we tried- you couldn’t link a template in one package to a template or USS in another.
The path format simply doesn’t -or didn’t?- support anything else but relative paths (and since the package folder is outside the asset folder, you couldn’t refer to one in a package)
Both the template binding path (src attribute) and the url function for things like style includes support project-wide paths using the standard convention for paths to packages (Packages/<package-identifier>). Both function correctly from my experience.