Search Unity

[Bolt] Help with wait/coroutines?

Discussion in 'Visual Scripting' started by agauger28, Jul 24, 2020.

  1. agauger28

    agauger28

    Joined:
    Jun 20, 2020
    Posts:
    17
    Hello, I'll try to keep it short. I'm trying to make an object "blink" in the game I'm working on and trying to figure out the best way to do this. I tried to do a Wait for (seconds) item but it throws an error saying that it only runs with a coroutine?

    I guess since I'm new to this all, I don't really know what a coroutine is or how to "initiate" one. Or, for that matter, is there a better way I could make this object blink?

    I hope I asked this in the correct place, and thanks for the responses.

     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Are you using some kind of visual scripting framework?

    You can just Google "Unity Coroutines" and learn all about them but I have no idea how they work with whatever visual scripting thing you're using.
     
  3. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    Select the green Update node and in the Graph Inspector window check the "Coroutine" checkbox.
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    PraetorBlue likes this.
  5. agauger28

    agauger28

    Joined:
    Jun 20, 2020
    Posts:
    17
    Oh my god, I am so embarrassed that the solution was so simple. Thanks for the help!
     
    johnjannone and ModLunar like this.
  6. lftxm

    lftxm

    Joined:
    Mar 15, 2023
    Posts:
    4
    I am so embarrassed that i can not understand how to solve it, Have you solved the problem of creating a coroutine?can you take a screenshot for me?Thanks a lot!!!!!!!
    (BTW,i am a chinese so i am so poor in english)
     
    Last edited: Mar 15, 2023
  7. X-Rayz

    X-Rayz

    Joined:
    Nov 15, 2020
    Posts:
    1
    Just check the box on the first block (On Start or On Update, or On button).

    You will see two green arrows if successful.

    upload_2023-3-15_16-45-58.png
     
  8. lftxm

    lftxm

    Joined:
    Mar 15, 2023
    Posts:
    4
    I have done it. but it no longer runs after "wait for seconds" . is any wrong with this node?
    upload_2023-3-16_10-6-11.png
     
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    I see you're running SetActive - implying that you are deactivating the GameObject. Coroutines will not run on deactivated GameObjects.
     
  10. lftxm

    lftxm

    Joined:
    Mar 15, 2023
    Posts:
    4
    But how can i achieve to destroy a gameobject after 2 seconds by visual scripting?
     
  11. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    The destroy function accepts a delay parameter, you don't need a coroutine for that.

    In general though you'd just run the coroutine on an object that is not being deactivated.
     
  12. lftxm

    lftxm

    Joined:
    Mar 15, 2023
    Posts:
    4
    oops! Thanks a lot!!!!! I have understood it now! But What do I need to do to enable it to destroy successfully and then continue to trigger the next step. upload_2023-3-17_13-9-18.png

    Thanks again!!!!!
     
  13. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    Destroy should be the last node in the sequence. If you need for something to happen after, you can use a Custom Event to communicate with a different graph that is not on the destroyed GameObject.

    There's also OnDestroy flow starting event node.

    Also, please create new threads for new issues that are not related to the originally posted message.