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 Access and manipulate VisualElements via Visual Script?

Discussion in 'UI Toolkit' started by Mawthra, Jun 3, 2023.

  1. Mawthra

    Mawthra

    Joined:
    Apr 16, 2023
    Posts:
    8
    I'm new to Unity and my main purpose for using it is creating UI prototypes and coming from decades of C4D usage, the most comfortable way for me to get into this is via a node editor like Visual Scripting

    I've seen lots of tutorials about controlling a UIDocument via C# scripts, but I'm trying to figure out how to access a VisualElement's properties and manipulate them that way (change a progress bars value, for instance to show how that would look/behave)

    Can anyone point me to a VS graph that shows how to do that or maybe a text diagram (Add this > Connect this, etc.)? Would be immensely grateful for any help
     
  2. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    1) Welcome to the Unity forum :)

    2) Accessing UI Toolkit in the visual scripting requires you to add some new nodes for UIDocument and Visual Element. You can enable them by adding these classes to the "Type Options" under: Edit > Project Settings > Visual Scripting > Type Options. There you will have to add "UIDocument" and "VisualElement". Then hit the "Regenerate Nodes" button (it takes a while).

    Once you have these nodes you will need a way to fetch the UIDocument from the scene. You can do that via "scene variables" (see: https://docs.unity3d.com/Packages/com.unity.visualscripting@1.7/manual/vs-variables.html). Create a new variable named "document" and drag in the UI Document from your scene.

    Sadly, that process is pretty cumbersome.

    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 in the faq ("I need to access properties ...") then there you will find some screenshots illustrating the process I described above. It also contains a lot of demo graphs.

    I hope this helps you to get started with your visual scripting adventure.
     
    Last edited: Jun 7, 2023
    Mawthra likes this.
  3. Mawthra

    Mawthra

    Joined:
    Apr 16, 2023
    Posts:
    8
    Tremendous thanks for this @_geo__ ! Your tool looks like a much easier way to get that working and can't wait till you release it... in the meantime I will look through your examples and use your tips to try and get that working.
     
    _geo__ likes this.
  4. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    @Mawthra : I now have a beta ready for testing. If you promise to get it once it's released I can send it to you :).

    Here is the teaser video:
     
    mariandev likes this.
  5. Mawthra

    Mawthra

    Joined:
    Apr 16, 2023
    Posts:
    8
    @_geo__ Even though you have no idea who I am, you have my word I'd 100% buy it on release ;) I'm in the industry working for a very large developer (front end artist) and need to use Unity just to throw together some quick UI prototypes and this would make things a whole lot easier, so yah... you've already got one sale :)
     
    _geo__ likes this.
  6. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    PM with beta access is out :)
     
    Mawthra likes this.
  7. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    Last edited: Jul 22, 2023
  8. Mawthra

    Mawthra

    Joined:
    Apr 16, 2023
    Posts:
    8
    _geo__ likes this.