Aditya
Aditya

Reputation: 23

How to update the namespace a custom control of Unity UIToolKit that is already inside a UI document

I was creating a custom control in unity and it was working all fine untill I decided to move the class of the control inside a namespace, if i am moving my code inside a namespace i am getting this error saying

Element 'LabelAutoFit' is missing a UxmlElementAttribute and has no registered factory method.

And after moving my control inside the new namespace I even changed my uxml to import this namespace like this

<LabelAutoFit /> to <New.NameSpace.LabelAutoFit />

but I am still getting the error. I tried asking chatgpt and it is suggesting me to use that old UxmlFactory class but I guess it is deprecated now. And I created another custom control but this time I kept it inside a namespace right from start and it is showing no issues. Now I want to know how to update the namespace of a custom control that is already inside an uxml document.

Upvotes: 1

Views: 49

Answers (1)

Chris R.
Chris R.

Reputation: 597

I had the exact same problem, and fully qualifying the class name in all project uxml was enough. Though I encountered these problems:

  • forgot at least one => same message
  • forgot to change in closing tag (when the custom component has children) like <New.NameSpace.LabelAutoFit>...</LabelAutoFit> => endless stream of error messages in console
  • didn't work until I closed all opened documents from UIBuilder window and restarted Unity.
  • In the UI Builder, check that your namespaces are found correctly in the library panel: Example of the library panel correctly finding custom elements newly added to namespaces

Upvotes: 0

Related Questions