I’m attempting to make a custom element (or a 'control ’ as it seems to be called in some docs?) but I’m getting this runtime error:
Element 'test.CountdownTimerElement' is missing a UxmlElementAttribute and has no registered factory method. Please ensure that you have the correct namespace imported.
UnityEngine.UIElements.UIDocument:OnEnable ()
I’m basing my implemetation on this which appears to be outdated.
This is my custom element class:
using UnityEngine;
using UnityEngine.UIElements;
[UxmlElement]
public partial class CountdownTimerElement : VisualElement
{
public new class UxmlFactory : UxmlFactory<CountdownTimerElement> { }
private Label _timerLabel;
public CountdownTimerElement()
{
_timerLabel = new Label();
Add(_timerLabel);
_timerLabel.style.fontSize = 24;
}
public void UpdateCountdown(int timeLeft)
{
_timerLabel.text = timeLeft > 0 ? timeLeft.ToString() : "Go!";
}
public void HideCountdown()
{
_timerLabel.text = string.Empty;
}
}
This is my template where the element is referenced:
<UXML
xmlns="UnityEngine.UIElements"
xmlns:test="test"
xsi="http://www.w3.org/2001/XMLSchema-instance"
engine="UnityEngine.UIElements"
noNamespaceSchemaLocation="../../../../../../UIElementsSchema/UIElements.xsd"
editor-extension-mode="False">
<VisualElement name="time-count-container" class="time-count-container">
<test:CountdownTimerElement name="countdownTimerElement" />
</VisualElement>
</UXML>
I’m not sure which specific UxmlElementAttribute
that I’m missing, as far as I’m aware there isn’t a requirement for an attribute, if there is I’m guessing it’s the “name” attribute which is used to select the element in scripts.
Any advice on what I’m doing wrong would be appreciated