Delay behavior

Updated on

July 27, 2022

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 functions - 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:

  1. Setting up the scene in Unity
  2. Example 1: Creating a delay with the Delay Behavior
  3. Example 2: Combining Delay Behavior and Behavior Sequences
  4. Example 3: Combining Delay Behavior, Repeat function and Wait For Completion function
  5. Next steps

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.

The workflow of our VR application looks 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. More information on setting up this workflow you can find in the tutorial on the VR Builder GUI.
  • 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. You can find additional information on the Grab object condition in the tutorial for picking and placing objects in VR. Help for letting the box move around the table is provided in the tutorial on creating consecutive steps and behaviors.
  • If the VR user succeeds, confetti rains from the top. Therefore, we added a Spawn Confetti behavior in step Confetti. For additional guidance on implementing the confetti highlight, consult the first tutorial on creating timed effects for enhanced user interaction.
  • 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 about the 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 Workflow 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. Note that in this example we must disable Repeat and enable Wait for completion is enabled.

Our sample 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.

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 VR Builder 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 the tutorial on the timeout condition!

Helpful links

Download Vr Builder