How can I change the namespace in custom control library?

Hello,

I was using my own UITK library since Unity 2021, with UxmlTraits and UxmlFactory. But with Unity 6, those classes will be deprecated.

To organize my project library in the UI Builder, I created a UxmlFactory that overrides the uxmlNamespace. But with the uxml codegen, the factory is now totally skipped.

[UxmlElement]
public partial class PieChart : Chart
{
    public new class UxmlFactory : UxmlFactory<PieChart, UxmlTraits>
    {
        public override string uxmlName => nameof(PieChart);

        public override string uxmlNamespace => "Leaframe.Charts";
     }

    ...
}

How can I achieve the same thing using the new Unity 6 codegen system? Because my project is organized by namespaces which could be really long. In the image below, you could see the PieChart which uses UxmlElement, and other components which still are in UxmlFactory.

Far as I can tell, doesn’t seem to be a way. Though there should really be an overload/parameter for [UxmlElement] that lets us define this.

1 Like

We dont support changing the namespace for an element, we expect it to match the namespace of the c# class. We do support changing the name via the UxmlElementAttribute name field.
We also support upgrading from one namespace to another with the MovedFromAttribute.
We dont have plans to support custom namespaces as far as im aware, ill discuss it further with the team. Better support for placing your elements in the UI Builder library is more plausible and something we are more likely to consider in the future.

Wondering why it is not possible to simply follow the Unity “path” component system by using

[UxmlElement("Leaframe/Charts/PieChart")]
public partial class PieChart : VisualElement {}

Exactly like [InspectorName("Path/To/Value")] or [AddComponentMenu("Path/To/Component")]

The name field is for UXML serialization, nothing to do with the UI Builder.
It mainly exists to support some custom elements we have where a UXML type does not match the c# name, e.g Template or Instance. Supporting paths would be something else that would need to be done in a different field or elsewhere, maybe another attribute.

1 Like