Delay behavior

Updated on

April 26, 2024

In this VR Builder tutorial, you will learn how to use the delay behavior to create timed effects. As the name suggests, the delay behavior is useful for delaying steps. First, we will explain how to use the delay behavior alone. To illustrate, we use the delay behavior to force a 10 second wait before performing the interaction to successfully complete the step. The result looks like this:

The second example is about using the delay behavior within a behavior sequence for more complex timed effects. In this example the VR user cannot grab the box until the entire sequence has run at least once. That is, the box must first move from its original position to a predefined position and back again before it can be grabbed. Once the VR user grabs the box  successfully, the steps are completed and confetti is raining from the top. The finished result looks like this:

In a third example the repeat and wait for completion function - two powerful features of the behavior sequence -  add additional complexity. Now the box moves from one position to another until the VR user grabs the green box. As soon as the user grabs the box in VR, confetti rains down from above. This way, the movement of an object is visually highlighted while interacting with it. Again, this is the end result:

Setting Up the Scene in Unity

This Unity scene has an environment that contains a floor and a table. On the table there is also a green box. We used basic Unity boxes for simplicity but VR Builder works with any 3D models as well.

Creating the Process in the VR Builder Process Editor

First, we set up the workflow in VR Builder as follows: 

  • The workflow created above consists of two steps. The first has a delay. Once the condition of the first step is met, the user enters the second step. The second step provides visual highlights for the user - confetti raining from the top - to show that they have successfully completed the VR application. If you haven't worked with the VR Builder GUI before, we recommend this tutorial. 
  • In our example, the success criterion is to grab the green box while it is moved. This requires a Move object condition and two position providers for the green box to move from box target 1 to box target 2. Also, we need to add a Grab object condition to the transition that leads to the success path and reference the green box in this condition. Check out the tutorial on how the move object condition and the tutorial on the grab object condition.
  • If the VR user succeeds, confetti rains from the top. We added a Spawn Confetti behavior in step Confetti for this. Check out this tutorial on how to do it.
  • If the VR user fails, they will hear a voice telling them that they have failed. We added a text-to-speech audio behavior for this. Learn more in this tutorial about how to make use of text-to-speech engines in VR Builder. 

Example 1: Creating a Delay with the Delay Behavior

In this Unity scene the VR user must grab the green box. However, since there is a 10-second delay, the VR user cannot exit the step until the waiting time has elapsed. Only then can the condition be fulfilled and the step completed. If the VR user needs more time than the given delay time to grab the box, they stay in the same step until they grab the box and the condition is met.

To create the delay behavior, select the step in the Process Editor. Next, go to Step Inspector > Behaviors > Add Behavior > Utility > Delay.

Set the delay to 10 seconds.

Combining Delay Behavior and Behavior Sequences

Delay behavior is very powerful when combined with behavior sequences, as more complex user interactions are possible. To illustrate, let’s create a complex, timed movement. If you don't know what a behavior sequence is, we recommend checking out the tutorial on consecutive steps and behavior sequences first to better understand what comes next. Note that "repeat" is disabled and "wait for completion" is enabled in this example. Will we explain these in the next section in detail.

Our example sequence will do the following:

  • Start: 00s: VR user enters VR application.
  • 02s: Green box moves to a predefined position (box target 1)
  • 04s: Box waits at the new position
  • 06s: Box moves back to new position (box target 2)
  • 08s: Box arrives at the starting position. Only then can the box be touched.
  • End: 10s VR user grabs the box and confetti rains down from above.

When the scene is now run in VR, the user cannot grab the box until the entire sequence has run at least once. That is, the box must first move from its original position to the right (Box Target 1) and back again (Box Target 2) before it can be grabbed. Once the VR user grabs the box  successfully, the steps are completed and confetti is raining from the top.

The result in Unity looks like this:

Combining Delay Behavior, Repeat Function and Wait For Completion Function

Two more powerful functions for using the delay behavior in behavior sequences are the Repeat function and the Wait for completion function. If you are not familiar with these concepts, read the tutorial on creating consecutive steps with behavior sequences before continuing here. 

If you want the box to move continuously from one position to another, you can select the Repeat checkbox.

Also, if you want the VR user to be able to grab the box at any time and complete the steps of the VR app without having to wait for the box to complete all the behaviors of the behavior sequence, you need to uncheck the Wait for Completion check box.

Now the box moves from one position to another until the VR user grabs the green box. As soon as the user grabs the box in VR, confetti rains down from above. This way, the movement of an object is visually highlighted while interacting with it. 

Next Steps

In this tutorial, you learned to delay user interaction by implementing the delay behavior. What if you want to validate if the VR user acts fast enough? Check out our Unity tutorial on the timeout condition! 

Ready to get Started?

Download Vr Builder