Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question UI Toolkit New Input System / ClickEvent not working

Discussion in 'UI Toolkit' started by hobohak, Jun 11, 2022.

  1. hobohak

    hobohak

    Joined:
    Mar 2, 2020
    Posts:
    6
    Hello,

    I am not able to connect a button click on a UI with a callback.
    The UI has a button "TestButton".
    In C# on the GameObject 'MainMenu' that uses the UI Document with the uxml I use the following code to find and register to the button:
    Code (CSharp):
    1. _root = _xml.rootVisualElement;
    2. var testButton = _root.Q<Button>("TestButton");
    3.  
    4. //Register
    5. testButton.RegisterCallback<ClickEvent>((evt) => { Debug.Log($"Clicked on '"); });
    When I debug, the Button gets found (strangely with width:NaN) and the registercall back line is fine.
    But If I click the button nothing happens. In Event debugger, the ClickEvent gets raised

    upload_2022-6-11_14-29-33.png

    I am using the 'New Input System' if this is somehow related.
    I had to add an EventSystem and the 'Input System UI Module'
    upload_2022-6-11_14-30-47.png
     
  2. hobohak

    hobohak

    Joined:
    Mar 2, 2020
    Posts:
    6