How to create package with UI Elements

I want to create package and access him though Package Manager β†’ Add package from git URL. To build package i use local project and create folder with package.json file inside ProjectName/Packages (as said in this instructions). And i want to use UI elements, so I create some layout in UI Builder and then try to save it in ProjectName/Packages/PackageName, then I get null ref exception

NullReferenceException: Object reference not set to an instance of an object
Unity.UI.Builder.VisualTreeAssetExtensions.DeepOverwrite (UnityEngine.UIElements.VisualTreeAsset vta, UnityEngine.UIElements.VisualTreeAsset other) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetExtensions.cs:44)
Unity.UI.Builder.BuilderDocumentOpenUXML.PostSaveToDiskChecksAndFixes (System.String newUxmlPath, System.Boolean needsFullRefresh) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:1069)
Unity.UI.Builder.BuilderDocumentOpenUXML.SaveNewDocument (UnityEngine.UIElements.VisualElement documentRootElement, System.Boolean isSaveAs, System.Boolean& needsFullRefresh, System.String manualUxmlPath) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:523)
Unity.UI.Builder.BuilderDocument.SaveNewDocument (UnityEngine.UIElements.VisualElement documentRootElement, System.Boolean isSaveAs, System.Boolean& needsFullRefresh, System.String manualUxmlPath) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Document/BuilderDocument.cs:282)
Unity.UI.Builder.BuilderToolbar.SaveDocument (System.Boolean isSaveAs) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Toolbar/BuilderToolbar.cs:368)
Unity.UI.Builder.BuilderToolbar.b__44_5 (UnityEngine.UIElements.DropdownMenuAction a) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Toolbar/BuilderToolbar.cs:500)
UnityEngine.UIElements.DropdownMenuAction.Execute () (at :0)
UnityEditor.UIElements.EditorMenuExtensions+<>c__DisplayClass0_0.b__0 () (at <7105be432fb64891b07085914e6cd5c1>:0)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[ ] options, System.Int32 selected) (at <7105be432fb64891b07085914e6cd5c1>:0)

UI Builder saves file though, but when I try to open it I get UI Builder: Cannot load .uxml files outside the Project.

UI Builder: Cannot load .uxml files outside the Project.
UnityEngine.Debug:LogError (object)
Unity.UI.Builder.BuilderToolbar:b__44_3 (UnityEngine.UIElements.DropdownMenuAction) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.18/Editor/Builder/Toolbar/BuilderToolbar.cs:478)
UnityEditor.GenericMenu:CatchMenu (object,string[ ],int)

How then should I create package if I want to use UI Elements?
Also I wonder how to locate files in package? Absolute path doesn’t work, because no matter where is file in local project, the package will be stored inside Library/PackageCache/PackageName@, so to get package folder to locate assets?

I’ve found this issue with same problem and solution from dev. I had missing letter is folder name, so have fixed it. There is no more errors when I save uxml to package folder, file also has proper uxml hierarchy inside. But there is still error when I try to open this file from UI Builder β†’ File β†’ Open. More strange that when I just double click on this uxml file on Project window UI Builder perfectly receives all data without any errors.
This is enough for me to continue development but still want to know what problem is and how can I fix it.

Hello! This is due to the fact that the development workflow in the UI Builder is not yet perfected for package development, unfortunately. We have it on our radar and will work on it, but for now just use the workflow that works (double clicking from the Project window) and hopefully soon both paths will work well! :sweat_smile:

1 Like

I work with a package but I use Import/Export from the Assets menu.