I really enjoy UI Toolkit in Unity 6. I have recognized its possibility.
While [UxmlFactory] and [UxmlTraits] are obsoleted before I have understood well, [UxmlElement] and [UxmlAttribute] are intuitive and very easy to use. So fun!
Then, I noticed that UI Builder can’t load [UxmlElement] VisualElement wrapped in a namespace on my script.
namespace MyProject
{
[UxmlElement]
public partial class MyElement : VisualElement
}
If I delete namespace nest from script, this custom control appears in UI Builder > Library > Project > Custom Controls.
I don’t think of it as bug, but it might mix up novice users. Troubleshooting custom control library compilation
This may be compilation issue, but not be included in this page.
This never happened to me I believe, and I always use a namespace for every type.
The namespace, if I recall correctly, actually changes the path to the control. Check if you can find it here or a variant thereof which uses the namespace eg:
Did you add the namespace after authoring a uxml file that uses the element? The uxml needs to include the full namespace and class name, so you can’t rename the class or change the namespace afterwards or you break the connection. To fix this you can use the MovedFrom attribute so it knows what the old name or namespace was.
Consequently, my custom control in namespace appears by utilizing MovedFrom attribute as you say.
Thank you! But I observed odd things about it.
Firstly, I actually used “Unity6Test” namespace with Root namespace function of Editor.
In fact, my problem was a custom control that created by this function doesn’t appear in UI Builder.
I tried to write over it to “MyProject” namespace on this script manually. Then I added MovedFrom attribute.
As a result, the problem is gone.
namespace MyProject
{
[MovedFrom(false, "Unity6Test")]
[UxmlElement]
public partial class MyCustomControl : VisualElement
{
[UxmlAttribute]
public float MyValue { get; set; }
}
}
Currently, if I don’t use “Root namespace” in the project setting > Editor, this issues wouldn’t happen in my environment.
So, it’s alright. I will continue to learn about UXML.
Thank you all!
Firstly, I apologize for my misunderstanding about this issue.
I couldn’t define this problem correctly.
But it’s very strange (for me.)
Correct problem is the following. If you use “Unity” word in front of name space, UI Builder can’t load its custom control.
This is what I encountered truely.
C# Project Generation and MovedFrom attribute are not concerned with this issue at all, sorry.
If you set on “Unity” on not head position, it’s ok.
Center position is alright, too.
BUT! This script can’t be loaded on UI Builder.
namespace UnityMyExperiment
{
[UxmlElement]
public partial class CustomControlTest : VisualElement
{
[UxmlAttribute]
public float Value { get; set; }
}
}
This issue doesn’t occur as long as you don’t start to write namespace name from “Unity”.
Thanks for all comment, again.
This is the conclusion what I have reached.