Can't find UI element with ID after building it with a script

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 :
7595896--942271--upload_2021-10-23_10-28-40.png

//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)

The UI Builder will simply add name="custom-name" to the uxml and the uxml will simply set the VisualElement.name property. This should absolutely work. Make sure that the element type is the correct one (in your setup code, you are creating a new VisualElement, but in the query, you are asking for a Label) and if it still doesn’t work, you can create an issue using “Help > Report a Bug…”.
Thanks.