Hello,
My script is creating some UI elements and I name them. I want to get them with another script but I can’t. It seems I can only “find” UI elements made with UI builder. For example :
// Script that create my VisualElement, everything works fine.
public VisualElement RaiderVisual;
// run OnEnable()
public RaiderSlot(string pseudo, string raiderClass)
{
RaiderVisual = new VisualElement();
Add(RaiderVisual);
RaiderVisual.focusable = true;
RaiderVisual.name = pseudo;
}
UI Debugger : my UI element has the “Korek” id name.
And I have my script to search for a UI element with name :
private VisualElement m_Root;
private VisualElement m_search;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
m_Root = GetComponent<UIDocument>().rootVisualElement;
m_search = m_Root.Q<Label>("Korek");
Debug.Log(m_search);
}
}
Result in game :
Null
UnityEngine.Debug:Log (object)
DebugerKeyInput:Update () (at Assets/Scripts/DebugerKeyInput.cs:27)
But if I change my script with “raid-boss-name” that is a UI element already made with UI builder :

//A UI element "raid-boss-name" is made with UI builder, no script.
m_search = m_Root.Q<Label>("raid-boss-name");
Label raid-boss-name (x:7.00, y:5.00, width:584.00, height:37.00) world rect: (x:390.00, y:10.00, width:584.00, height:37.00)
UnityEngine.Debug:Log (object)
DebugerKeyInput:Update () (at Assets/Scripts/DebugerKeyInput.cs:27)
