Search Unity

Resolved Can you show game object on button press using bolt?

Discussion in 'Visual Scripting' started by jasonasaad2, Jan 19, 2021.

  1. jasonasaad2

    jasonasaad2

    Joined:
    Nov 30, 2020
    Posts:
    51
    Ok, I like visual scripting, I am not really good with C# and I tried but it failed.
    There isn't compiler errors, it just doesn't do anything
     

    Attached Files:

  2. mintman

    mintman

    Joined:
    Nov 28, 2013
    Posts:
    4
    I'm not exactly sure what the problem is, but there's a few things to check.

    First make sure the Flow Machine isn't on the object you want to activate.

    The object that runs the flow machine needs to be active. There is no way around this. This is the same for scripts that run any Unity lifecycle methods like
    Update()
    or
    Start()
    . Start and Update in this flow machine won't be run if the object is off. If you haven't already, I'd suggest making a parent object or a sibling that only holds the flow machine.

    Decide between using a Coroutine or using syncronous code
    You're using
    Update
    with the coroutine flag checked on the unit. This is suspicious to me. This will start a coroutine every frame, which is unnecessary. If you plan to expand upon it and have some kind of sequential logic, you may have a real use case for a coroutine, but in that case I would probably choose to start it from the Start unit, and delete the duplicate.

    If you're not using a Coroutine, just set the values on Update
    It should look closer to the attached image. (I've mocked up a Super Unit to fit in for your call to GetButtonDown.)

    upload_2021-1-19_21-18-59.png

    When making a loop, use a While Unit
    Bolt will stack overflow if you cycle flows as you have done in your attached image.

    If you are running a coroutine and you actually want an endless loop, then tie a Boolean Literal set to True to the input of a While Unit. You should only ever consider this on coroutines and ensure you have a "Wait" unit somewhere off of the While Unit. (eg. Wait Next Frame, Wait Until). Unity will lock if you don't, and you will feel a little bit bad every time it happens, but you'll recover.
     
    ericb_unity and Dudusstar like this.
  3. jasonasaad2

    jasonasaad2

    Joined:
    Nov 30, 2020
    Posts:
    51
    Yeah I was new to visual scripting, didn't know much, thanks for explaining all this