July 27, 2022
In this VR Builder tutorial, you will learn how to snap different objects into the same snap zone.
This Unity scene has the same setup as the introductory tutorial for snap zones. If you haven't watched this tutorial yet, we recommend that you do so before continuing.
The steps of our VR application are as follows: in the first step we grab either of both bricks. In the second and last step, we place either the blue or the pink brick into the target position. Please note that to automatically activate the second step Snap brick after you complete the first step (either by grabbing the blue brick or the pink brick), you need to create a second path between the first and second steps in the Workflow Editor. The final result of the workflow looks like this:
You can find further help on how to use the VR Builder GUI in the tutorial on the Workflow Editor. Also, both the blue and the pink bricks are made grabbable, whereas only the blue brick has a snappable property, as well. If you are not familiar with how to grab and snap objects in VR, please read the introductory tutorial about snap zones.
So far it is only possible to snap the blue brick in the existing snap zone - the Blue Brick_SnapZone. However, it is not yet possible to snap the pink brick into the same snap zone. Our goal now is to snap the pink brick into the existing snap zone and not a new one. To snap the pink brick into the Blue Brick_SnapZone, we need to add a Snappable property to the pink brick and reference the blue brick's snap zone.
Like before with the blue brick, we use the Fix it button to add the needed properties automatically. Then, add another Snap Object condition to the other transition and reference the pink brick. Then, press again the Fix it button. Since we don't want to snap the pink brick into a new snap zone, but into the existing one, we need to reference the Blue Brick_SnapZone as the Zone to snap into.
The condition is now fulfilled, but the snap zone still is not accepting the pink brick. The reason is the following: Having selected the Blue Brick_SnapZone, go to the Step Inspector and access the Is Training Scene Object Validation component. There you will find a list of hidden objects called Accepted Training Scene Objects.
There you can see that the Snap Zone Generator for the existing snap zone has automatically referenced the blue brick as the only accepted training scene object. This ensures that only the correct object, in this case the blue brick, can be placed into the Blue Brick_SnapZone. And since the pink brick is not referenced as an Accepted Training Scene Object, it is not accepted by the Blue Brick_SnapZone.
For the Blue Brick_SnapZone to accept the pink brick, you must add the pink brick to the Accepted Training Scene Objects. To add a new element, select + and reference the pink brick.
Although this is an unnecessary step, you can change the unique name of your game objects afterwards. However, you have to be careful here not to break the already existing references. For example, let’s change the unique name of the Blue Brick_SnapZone, e.g. to Brick_SnapZone as demonstrated in this tutorial.
Note, however, that changing the unique name will remove the old snap zone references and will corrupt the Unity scene. To fix this issue, with the Brick_SnapZone selected you must reference the game object again in the appropriate fields of the Step Inspector > Transitions > Conditions > Snap Object > Zone to snap into.
In this VR Builder tutorial, you learned how to snap different objects into the same snap zone. However, snap zones are just one way to guide your users more intuitively in VR. What if you also want to give them audio instructions on what to do next? Check out our tutorial on the VR Builder text-to-speech (TTS) engine.