UIElements Buttons only Fire Once per Run in Unity Editor

UIElement Button Click Fires Once.

I’m building a “pop-up” NumberPad (NumPad) using the UIToolkit.
The way it’s supposed to work is:

  1. I have an empty GameObject (objNumPad) with a UIDocument attached to it.
  2. To display my NumPad, I activate the objNumPad, and I deactivate it to hide it.
    Here is my UIToolkit Template:
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <Style src="project://database/Assets/UI/NUMPAD/NumPadSS.uss?fileID=7433441132597879392&amp;guid=2e42f5cd60bfc684c95ed39187966fae&amp;type=3#NumPadSS" />
    <ui:VisualElement name="screen" style="flex-grow: 1; width: 100%; height: 100%; align-items: center; justify-content: center;">
        <ui:VisualElement name="NumPad" class="NumPad">
            <ui:VisualElement name="ButtonRow" class="ButtonRow">
                <ui:Button text="7" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd7" class="NumPad-Button" />
                <ui:Button text="8" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd8" class="NumPad-Button" />
                <ui:Button text="9" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd9" class="NumPad-Button" />
            </ui:VisualElement>
            <ui:VisualElement name="ButtonRow" class="ButtonRow">
                <ui:Button text="4" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd4" class="NumPad-Button" />
                <ui:Button text="5" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd5" class="NumPad-Button" />
                <ui:Button text="6" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd6" class="NumPad-Button" />
            </ui:VisualElement>
            <ui:VisualElement name="ButtonRow" class="ButtonRow">
                <ui:Button text="1" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd1" class="NumPad-Button" />
                <ui:Button text="2" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd2" class="NumPad-Button" />
                <ui:Button text="3" parse-escape-sequences="true" display-tooltip-when-elided="true" name="cmd3" class="NumPad-Button" />
            </ui:VisualElement>
        </ui:VisualElement>
    </ui:VisualElement>
</ui:UXML>

My design almost works: it pops up every time I request it (active objNumPad), and the Click events work the first time I click on one of the NumPad Buttons, but then the NumPad is deactivated. When the NumPad is subsequently re-activated and I again click on a Button, the click events do not fire.:

NumPad Problem Demo

Here is the script for my NumPad:

using System;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.UIElements;

using static UnityEditor.PlayerSettings;

public class NumPadScript : MonoBehaviour
{
    static UIDocument _doc;
    VisualElement _root;
    Button _cmd1;
    Button _cmd2;
    Button _cmd3;
    Button _cmd4;
    Button _cmd5;
    Button _cmd6;
    Button _cmd7;
    Button _cmd8;
    Button _cmd9;
    int _numSelected;

    // Start is called before the first frame update
    void Start()
    {
        _doc = GetComponent<UIDocument>();
        _root = _doc.rootVisualElement;
        _cmd1 = _root.Q<Button>("cmd1");
        _cmd2 = _root.Q<Button>("cmd2");
        _cmd3 = _root.Q<Button>("cmd3");
        _cmd4 = _root.Q<Button>("cmd4");
        _cmd5 = _root.Q<Button>("cmd5");
        _cmd6 = _root.Q<Button>("cmd6");
        _cmd7 = _root.Q<Button>("cmd7");
        _cmd8 = _root.Q<Button>("cmd8");
        _cmd9 = _root.Q<Button>("cmd9");
        _cmd1.clicked += _cmd1_clicked;
        _cmd2.clicked += _cmd2_clicked;
        _cmd3.clicked += _cmd3_clicked;
        _cmd4.clicked += _cmd4_clicked;
        _cmd5.clicked += _cmd5_clicked;
        _cmd6.clicked += _cmd6_clicked;
        _cmd7.clicked += _cmd7_clicked;
        _cmd8.clicked += _cmd8_clicked;
        _cmd9.clicked += _cmd9_clicked;
    }


    private void Update()
    {
        // deactivate the NumPad by pressing escape.
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            g.SelectedSudoCube.SetBackcolor(Color.white);
            g.SelectedSudoCube = null;
            g.NumPadSwitch(false);
        }
    }
    private void click(int v)
    {
        g.UserValueCandidateSelected = v;

    }
    private void _cmd1_clicked() { click(1); }
    private void _cmd2_clicked() { click(2); }
    private void _cmd3_clicked() { click(3); }
    private void _cmd4_clicked() { click(4); }
    private void _cmd5_clicked() { click(5); }
    private void _cmd6_clicked() { click(6); }
    private void _cmd7_clicked() { click(7); }
    private void _cmd8_clicked() { click(8); }
    private void _cmd9_clicked() { click(9); }

    /****************************************************************
     * I'd like to be able to place the NumPad in chosen locations in
     * the game area.  
     * I don't know how to do this, if anyone has advice for me in this
     * regard, I'd be grateful for that too.
     ****************************************************************/
    //public void SetPosition(Vector3 pos)
    //{
    //    try
    //    {   /**************************************************************
    //         * doesn't work yet, but this is the direction I thought might 
    //         * be right.
    //         **************************************************************/
    //        _doc = GetComponent<UIDocument>(); // returns null
    //        _root = _doc.rootVisualElement;
    //        _root.layout.Set(pos.x, pos.y, 400f, 400f);
    //    }
    //    catch (Exception x)
    //    {
    //        print(x.Message);
    //    }
    //}
}

Additionally, I should explain what “g.NumPadSwitch()” is:


public class g : Singleton<g>
{
    public static GameObject NumPad { get; set; }
    /// <summary>
    /// Toggle the NumPad by setting the UIDocument's
    /// parent-object active or inactive.
    /// </summary>
    /// <param name="offOn"></param>
    public static void NumPadSwitch(bool offOn)
    {
        NumPad.gameObject.SetActive(offOn);
    }
}

There are more globals in my (g)lobals class, but I don’t believe they are germane to the problem.

I hope I’ve explained my problem clearly. I’ll check in regularly to check for responses.
Please let me know if you need more information.

Thank you very much,

Rosco-y