Search Unity

Resolved Visual Scripting with a UI Button - help or advice request -

Discussion in 'Visual Scripting' started by puddingstone, Sep 2, 2021.

  1. puddingstone

    puddingstone

    Joined:
    Aug 6, 2021
    Posts:
    3
    Visual Scripting with a UI Button - help or advice request -
    Hi I've just started learning Unity and have been pleased to find that there is a "Introduction to Visual Scripting" tutorial - that's great as I'm not a coder (yet...) but I'm having problems finding online advice and more visual scripting tutorials -as I think its so new to v2021.1. (I know it was previously called bolt but that stuff seems to have slightly different implementation) so am focussing on the current release.

    I'm Interested in controlling UI buttons via visual scripting.
    I have a primitive that can spin - I just want to start and stop it spinning with the UI button,
    I'm guessing that I need to look at a "Button.onClick" event unit, but i cant work out what to do to link up the UI Button. any tips, or examples that anyone can share please>?
    visual-scripting-a-button.jpg
    P.S. if there is a more appropriate location to post this please let me know
    thanks
     
  2. Renicon13377

    Renicon13377

    Joined:
    Mar 1, 2021
    Posts:
    4
    upload_2021-9-4_1-19-58.png

    This should work. When you create your button UI, drag and drop it into the "On Button Click" node. Make sure the object you want to rotate is in the "Transform Rotate" node as well.
     
  3. puddingstone

    puddingstone

    Joined:
    Aug 6, 2021
    Posts:
    3
    Thanks for the input Renicon13377 - no luck after looking at your illustration.

    Regarding your comment If you don't mind clarifying, I only seem able to drag a button that has been made into a prefab onto the "on button click" event node - (as i'm so unfamiliar) - is that expected>?

    I'm wondering if i need to implement any special config in order to get the button to see or talk to the Visual script.

    I've seen the info here : is this optional or a requirement for interacting with a UI button via VS (cant tell if this is relevant of not)


    Next query - see below:

    upload_2021-9-6_14-38-13.png

    Assuming the button interaction is being setup in a visual script graph - is this "on Click ()" field in the button inspector also need to be populated>? could it be conflicting>? if it is needed, how should it be configured?

    Thanks in advance
     
  4. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167
    When you add the "On Button Click" event node in your graph, you don't need to put anything in the "On Click ()" section of the button component. As long as your script machine or state machine is on the same Game Object that containing the button component, you are ready to consume the click event.
     
  5. puddingstone

    puddingstone

    Joined:
    Aug 6, 2021
    Posts:
    3
    thanks for clarifying ericb_unity.1587671

    I Still can't get a button to show anything using a VS graph as I don't know how to set it up. Can you think of any specific examples, tutorials to recommend or give some detailed screenshots on the basics please
    thanks in advance
     
  6. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167
    This is how you should make the setup.

    1. Make sure you have a script machine with a graph on your object like on the following screenshot. upload_2021-9-9_9-56-12.png
    2. Right click in the graph to add a new node and add an "On Button Click" node in the graph.
      upload_2021-9-10_9-44-46.png
    3. Link anything you want to do after a user click on a button having this script.
      upload_2021-9-9_10-7-51.png
    4. Result
      buttonclick.gif
     

    Attached Files:

    Last edited: Sep 10, 2021
  7. runtiger

    runtiger

    Joined:
    Jan 9, 2022
    Posts:
    3
    how do i make it when you hold click on a button it will keep holding and not only click once? thank you in advance
     
  8. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167
    I would suggest creating a new thread with this subject.
     
  9. Slinky921

    Slinky921

    Joined:
    Apr 15, 2023
    Posts:
    5
    Does not even work