How do wait for seconds?

palebluesean 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 13

Im not able to find a script node to wait for X seconds. Is there something like that im missing?

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by palebluesean 4 years ago

Under Events/Time/On Timer Elapsed is available. For a timer to use with the event, I am still looking myself.


You can indeed use the On Timer Elapsed event for this. There is no "timer" object to use with it, you only need to pass a number of seconds.

Note that this is time that has elapsed since the graph has been "entered". For flow machines, that's time since the component was enabled. For states and state transitions, that's the time since the state was entered.

If you want to create complex chains or conditions for a wait, you should use a state machine with multiple states or transitions using On Timer Elapsed. If you let me know what you want to accomplish more specifically, I could maybe point you in the right direction.

This is the example I was trying to put together for him, not sure if this was what he specifically needed, but for me, I was looking for a timer to put in between events, in this example, On mouse go down, wait 10 seconds then continue type as the On Timer Elapsed in this case would be an event, though I am sure it can be nested and separated.

There used to be "coroutine-like" wait nodes like this, that had a control input and output, but it added a lot of complexity to graphs by introducing parallel flow. It was also extremely confusing to use these coroutines in loops, or to break them.

For the moment then, I decided to remove these "wait" nodes and rely on state graphs, which can do all they could and even more. In your example above, you could structure it like that:

Parent state machine:


Set color state:

Yes. I have been focussing on Flow Graphs at the moment, but in my example, there is no reason I could not use a State Graph. Hopefully that addresses his question as well. Ty.

This answers my poorly worded question! I was indeed trying to have a "wait" in the middle of a state machine, so your example was perfect. Thank you!

Spoke too soon. I was able to recreate your example. Then i tried to extend it and im not seeing what I expected, which means I'm doing something wrong.

Here is the top level state. I expect to wait until i press the mouse button (this works) and then enter the "Wait" Flow. Here I expect to wait until the timer has elapsed and then trigger a state change (this doesn't work). This should send me over to the "Set Random Number" state.

Instead what I see is, on clicking the mouse i jsut move through all the states instantly, not waiting in the " Wait" state. What am i missing?

Wait State:


OK i figured it out.

The notion of having seperate nodes for the events that will cause a state transition is new to me. Playmaker lumps all of this into a single state (for better or worse). I think this ultimately makes more sense and is readable at a top level, but just new for me.

Glad you got it working. If you want the top level graph to be more tidy, you can change the State Transitions Reveal option to something like On Hover under Preferences > Bolt > State Graphs.

I do think that graph you sent can be simplified (getting rid of the middle state) by using On Timer Elapsed instead of On Enter State in your Set Random Number state though. Would that work for you?

Could you show me what you mean? Im trying to achieve that and having no luck.

Exactly like the example I posted above:


Two states and one transition.

What exactly can't you get to work?


My apologies. Yes I was able to successfully recreate your first graph. I misunderstood your suggestion and went down a weird road. Thanks for bearing with me. This is my first node based editor and even though it shares similarities with Playmaker, it is requiring a brain adjustment for me. I guarantee there will be a heck of a lot more posts like this one to follow.

Thanks for the swift and helpful responses!

No problem, glad to help.