A game about forced loneliness, made by TACStudios
1# Time nodes 2 3> [!NOTE] 4> For versions 2019/2020 LTS, download the Visual Scripting package from the [Unity Asset Store](https://assetstore.unity.com/packages/tools/visual-bolt-163802). 5 6Time nodes include timer, cooldown and wait nodes. 7 8## Wait 9 10Wait nodes delay the execution of the rest of the script. The delay can be a set amount of seconds or a condition that must be fulfilled before moving on. 11 12Asynchronicity (delayed execution) in Unity is handled by [coroutines](https://docs.unity3d.com/Manual/Coroutines.html) (not multithreading). You need to inform visual scripting to run the script as a coroutine in order to support wait nodes. To do this enable the **Coroutine checkbox** on the initial event that starts the script. Do this in the graph inspector. 13 14![](images/vs-time-coroutine-wait-nodes.png) 15 16A small dual-arrow icon appears on the event, indicating that it runs as a coroutine. 17 18If the coroutine checkbox is not enabled, an error at runtime indicates a port 'can only be triggered in a coroutine' when reaching a wait node. 19 20All wait nodes are also used inside loops and sequences. 21 22### Wait For Seconds 23 24The Wait For Seconds node is the simplest and most common wait node. It delays the execution by a certain number of seconds. 25 26 27![](images/vs-time-wait-for-seconds-node.png) 28 29### Wait Until 30 31The Wait Until node stops execution until a given condition is met. For example, you could wait until an object is close enough. 32 33 34![](images/vs-time-wait-until-node.png) 35 36### Wait While 37 38The Wait While node is the opposite of the Wait Until node: it stops execution as long as a given condition is met. For example, you can wait while an object is out of range. 39 40 41![](images/vs-time-wait-while-node.png) 42 43### Wait For Frame 44 45As the name implies, Wait For End Of Frame and Wait For Next Frame nodes delays execution until a specific point in Unity's update loop is met. For more information, see: [Execution Order of Events](https://docs.unity3d.com/Manual/ExecutionOrder.html). 46 47### Wait For Script 48 49The Wait For Script node delays execution until all input scripts have been entered at least once. It's a useful way of grouping conditions that occur over multiple events or frames. In other languages, this concept is sometimes called "promises". 50 51## Cooldown 52 53 54 55 56![](images/vs-time-cooldown-node.png) 57 58The Cooldown node implements a time restriction when the input script can only be triggered a limited number of times. 59 60When the cooldown is available, the input script gets transferred to the Ready port. When it is not, it gets transferred to the Not Ready port. 61 62The Duration port determines how long it takes for the cooldown to become available again. Checking **Unscaled** makes it ignore the [time scale](https://docs.unity3d.com/ScriptReference/Time-timeScale.html). 63 64The Tick port gets called at every frame while a cooldown is active. It is a good place to update any GUI code that show an indicator of the remaining duration until the action can be called again. In order to get that value, you have two options: 65 66- Remaining, which returns the number of seconds until ready, and 67- Remaining %, which returns a value between 0 and 1, respectively from ready to not ready. 68 69As soon as the cooldown is ready, the Completed port is triggered. There is no need to constantly pass input script for this port to get triggered. 70 71Finally, you can force the cooldown to become ready and reset its internal timer by triggering the Reset port. 72 73For example, a simple cooldown firing mechanic with a masked sprite and text that indicates how much time is remaining until it can fire again. 74 75 76![](images/vs-time-cooldown-node-example.png) 77 78## Timer 79 80 81 82 83![](images/vs-time-timer-node.png) 84 85The Timer node implements and monitors a time pausable progression. 86 87The Duration port determines how long it takes for the cooldown to become available again. Checking Unscaled makes it ignore the [time scale](https://docs.unity3d.com/ScriptReference/Time-timeScale.html). 88 89A timer is started by triggering the Start input, which in turn triggers the Started output. 90 91It can be paused and resumed with the Pause and Resume inputs, or it can alternate between these states with the Toggle input. 92 93The Tick port gets called at every frame while a timer is active. In order to get the time measurements, you have two options: 94 95- Elapsed, which returns the time since the timer was started, or 96- Remaining, which returns the time until the timer completes. 97 98You can get each of these measurements in absolute number of seconds, or in %, which returns a value between 0 and 1. This is useful for lerping. 99 100As soon as the timer finishes, the Completed port is triggered. 101 102For example, a simple autodestroy mechanic on a sprite that is progressively colored red before being destroyed. 103 104 105![](images/vs-time-timer-node-example.png)