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. Dismiss Notice

Question I need help integrating UI Toolkit and Visual Script

Discussion in 'UI Toolkit' started by sanabriamattos, Jun 9, 2023.

  1. sanabriamattos

    sanabriamattos

    Joined:
    Jun 28, 2022
    Posts:
    8
    Good morning, I apologize for the inconvenience, and I apologize in advance for my English. My native language is Spanish. I need help integrating UI Toolkit with Visual Script. I'm developing a demo app, and I think it would be easier for me to do it visually rather than through code since I'm still learning C#. I already have the interface done in UI Builder, and it works perfectly with C#, but I would like to transfer the little I've done to Visual Script. Please help, I really appreciate your time. I have already searched a lot on the internet, but I couldn't find enough information to make it work. I have attached a screenshot of what I have so far. At the moment, I need help making the test button print some text in the console when clicked. Once I can connect that, I think I can understand how it works and move forward with the rest.

    Thank you very much again for your help.

    Captura de pantalla (47).png Captura de pantalla (48).png
     
  2. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    Hi,
    you would need to use the result from the Query extension node (which is a VisualElement) and register the button events on it. And you would have to hook a trigger into the Q node to make it actually execute.
    upload_2023-6-12_22-2-29.png

    The key part would be to register the callbacks on the button. To do that you could implement a custom c# Event<T> node:
    Code (csharp):
    1. registerCallbacks(VisualElement ve) // That's the result from the Q Node
    2. {
    3.    var button = ve as Button;
    4.    if (button != null)
    5.    {
    6.        button.RegisterCallback<ClickEvent>(handleEvent);
    7.    }
    8. }
    9.  
    10. protected void handleEvent(ClickEvent evt)
    11. {
    12.    // Do your stuff
    13. }
    I have written an asset that automates and streamlines the process, though it's not released yet. However, the manual is already online: https://kamgam.com/unity/UIToolkitVisualScriptingManual.pdf
    If you look into it you can see how this could be done (I did it with custom nodes).

     
    Last edited: Jun 14, 2023
  3. sanabriamattos

    sanabriamattos

    Joined:
    Jun 28, 2022
    Posts:
    8
    Thank you very much, it worked !
     
  4. riek100

    riek100

    Joined:
    Sep 16, 2018
    Posts:
    6
    Any update on this tool? I would love to purchase it!
     
    _geo__ likes this.
  5. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111