Skip to content

Lab 2: Your Own Plank Experience

The goal of this lab is to give you experience working with VR in Unity and importing assets from the Unity Store.

You will create your very own "plank experience", except instead of a city scene, you will have the user step out into a world of your own making (a dinosaur village, space, your hometown, etc.). For this experience, you don't need to have the plank be 50 meters in the air; you just need to have the user open an elevator and step out into your world.


Part 1: Setup Unity for VR

Let's setup Unity for VR development. You can repeat these steps in the future every time you are starting a new VR project.

Create a new project

Open Unity Hub and create a new "3D Core" project. You can reference the steps from HW 1 if you need a refresher.

Name this project "<YOUR NAME> Plank Experience", replacing <YOUR NAME> with, well, your name.

Create the project and open it in the Unity Editor.

Switch Build Platform to Android

Next, go to the File menu at the top and select Build Settings.... In the dialog that appears, select Android under the Platform section, and then click on Switch Platform at the bottom.

While we're here, also click the Add Open Scenes button to add the SampleScene to the build. You should see something like this:

Once done, you can close this dialog.

Import the Oculus Integration Package

Since we are working with the Meta Quest 2 headsets, we'll focus on using their official Unity SDK.

Note

Unity also provides it's own cross-platform XR runtime through the XR Plugin Management system and the XR Interaction Toolkit, but we'll be using the Oculus Integration Package since it is tailored to our headsets.

The first thing we want to do is download and install the Oculus Integration Package. The latest version (v56) has some issues with the XR simulator (which we want), so let's download version 54.1 instead. Go to https://developer.oculus.com/downloads/package/unity-integration/54.1 and click on the big blue download button. Accept the terms of the license and click Download. Save it somewhere you can easily access.

Go back to your project in the Unity Editor. In the Project View, right-click the Assets folder. In the menu that pops up, go to Import PackageCustom Package....

In the file dialog that opens, find the Oculus Integration Package you just downloaded and select it. When a small window showing the contents of the package appears, click the Import button in the lower-right corner. Wait for Unity to finish importing the package.

If prompted to "Help improve the Oculus SDKs", select "Don't send". They aren't getting any of our data!

If you are asked to restart the editor, please select yes.

You may also be asked if you want to perform a cleanup operation:

Click Show Assets (Recommended) and then click Clean Up (Recommended) in the dialog that follows. Continue to confirm any additional dialogs. This will clean up the package.

When asked to upgrade the spatializer, select upgrade.

Finally, if asked to restart the editor, please select yes again.

Now we want to configure the project for VR. In the Oculus menu at the very top, select ToolsProject Setup Tool.

In the dialog that opens, select the Android tab on the right (it's the one that looks like a little robot). Then click the Fix All button. You may need to press this button twice to apply all the fixes.

Also click Apply All for the recommended items.

Repeat these steps to apply all fixes and recommended settings for the first tab (Desktop) too.

Add a Rig and Interaction

The next step is to add in a virtual headset and controllers. Because the headset is technically the "camera" in VR, go ahead and delete the Main Camera from the Scene. You can find it in the Hierarchy on the left.

Now, in the Project View, you should see an Oculus folder in the root Assets folder. Open the Oculus folder, then the VR folder, then Prefabs. You are now in the Assets/Oculus/VR/Prefabs/ directory. You should see something like below:

Find the prefab named OVRCameraRig and drag it into your Hierarchy.

Info

A prefab is a GameObject that has been pre-configured and saved so that it's reusable. Consider it like a template or a class, where you can easily create new instances of that class. You can even create your own prefabs!

This GameObject represents the user's origin in VR (typically the center of their VR playspace/boundary) as well as the position of the headset and controllers relative to that origin. If you expand it, you can see multiple GameObjects to represent the left eye, right eye, left hand, etc.

Click on the main OVRCameraRig object in the Hierarchy. In the Inspector, inside the OVR Manager component, set the Tracking Origin Type dropdown to Floor Level. This makes sure that the origin is set to the floor (so that the virtual floor matches the real floor).

Now we want to add the controllers. In the Project View, navigate to Assets/Oculus/Interaction/OVRIntegration/Runtime/Prefabs/. You should see a prefab named OVRInteraction. Drag this prefab onto the OVRCameraRig object in your Hierarchy. This will make it a child of the camera rig:

Now, we just need to add controllers (or hands, which we'll explore in the future).

Add Controllers

In the same folder with the OVRIntegration prefab, you will find an OVRControllers prefab. Drag this prefab onto the OVRInteraction object in your Hierarchy. This will make it a child of the interaction GameObject:

The controllers should be set up automatically if you dropped it onto the OVRInteraction object. If needed, you can also follow the instructions here to manually set the controllers.

You're all set up for VR in Unity!!! 🎉

You can repeat these steps for any new VR project you create.


Part 2: Creating the Elevator

Let's get the scene started by adding an elevator and a plank!

Import Elevator Package

I've already modeled and animated an elevator for you. Download the following Unity package: elevator.unitypackage.

Import it into your project. Remember, you can do so by going to the Project View, right-clicking the Assets folder, then selecting Import PackageCustom Package....

Once the elevator package is imported, go to AssetsElevator in the Project View. You should see an Elevator prefab.

Drag this prefab into your Hierarchy (take care to NOT accidentally make it a child of something else). Set the elevator's position to (0, 0, -0.25). This will center the camera rig in the elevator.

Add a Button

Let's add a button so that the user can open and close the doors! Let's make it a child of the elevator's panel. Go ahead and expand the Elevator GameObject in the Hierarchy.

Right-click on the Panel object in the Hierarchy and go to 3D ObjectCylinder. Rename this new cylinder to Button. Rotate, resize, and move the cylinder so you have a big button in the center of the panel.

If you look in the Assets/Elevator/Materials folder, there is a red material called Button. Apply this to the button by dragging it from the Project View and dropping it onto the button. You should have something like below:

Add Interactivity

We'll do a simple "ray-based" interaction so the user just needs to point the controller at the button and pull the trigger to open the doors (no need to go up and touch the button!). The Oculus integration provides two components to make this work: a RayInteractor and a RayInteractable.

Info

If you need to reference these steps later, the Meta Quest Developer Documentation has more detailed tutorials. See the Create Ray Interactions section.

Ray Interactor

Let's set up the RayInteractor first! In the Hierarchy, expand the OVRCameraRig, then OVRInteraction, then OVRControllers, then expand both the LeftController and RightController objects.

In the Project View, use the search bar to search for ControllerRayInteractor. Alternatively, you can find it in Assets/Oculus/Interaction/Runtime/Prefabs/Ray/.

Drag the ControllerRayInteractor prefab onto the ControllerInteractors object under LeftController in the Hierarchy:

Now click on that ControllerInteractors object. In the Inspector, expand the Interactors section under the Best Hover Interactor Group component. Click the "plus" to add a new element. Set the elemtent to the ControllerRayInteractor you just added. You can do this by clicking the little circle with a dot, or by dragging the ControllerRayInteractor from the Hierarchy onto the box that says None (IInteractor).

Now repeat these steps to add another ControllerRayInteractor prefab to the ControllerInteractors object for the right controller. Make sure to also set the Best Hover Interactor Group for that controller.

This will make laser rays shoot out of the controllers, perfect for selecting buttons!

Ray Interactable

Now, let's add a RayInteractable to the button so that the controllers can interact with it. Select the Button in the Hierarchy. In the Inspector, add a new Collider Surface component. Set the Collider property to the Capsule Collider right above it. You can drag the Capsule Collider component and drop it onto the box that says None (Collider)

Now add a new RayInteractable component. Set the Surface property to the Collider Surface you just created. Again, you can just drag and drop the Collider Surface onto the property selector.

Let's make the button open and close the doors when the user presses it. Add an Interactable Unity Event Wrapper component. What this does is it lists all the actions to occur when the user hovers on the button, selects the button, etc. First set the Interactable View property to the Ray Interactable component you just created. Guess what? You can drag-and-drop!

Next, go down to the When Select () section and click the "plus" icon. Now, we are selecting a function to call when the user presses the button. Set the None (Object) property (this is the target) to the Elevator GameObject. Then, in the drop-down on the right, select AnimatorSetTrigger (string).

Underneath the dropdown is a textbox for you to enter an argument to be passed to the Animator.SetTrigger method. This is a specific trigger I've set that will toggle the doors open and closed. Set the textbox to the string toggle.

Create a Plank

Now, create a cube in your scene and adjust its transform so that it forms a 1 meter plank sticking out the door of the elevator. Rename the cube to Plank. In the Project View, create a folder in Assets called Materials. Inside this folder, create a new material called Plank. Set it to be a plank-y color and then set the Plank object in your scene to the Plank material in your assets. You can do this by dragging and dropping the material onto the object in the Scene View.

You have an elevator and a plank! That's a great starting point!

(Optional) Test Using the Simulator

Warning

There are reports that the simulator does not work properly on MacOS. In the case that it is not working, please skip this section and continue with the rest of the lab.

Before we build the app and test on the headset, we can run it on our computer using the Meta XR Simulator. This is included in the Oculus Integration Package. In the Oculus menu at the top, go to Meta XR SimulatorActivate.

Now, run the project. You should see a new window popup. This is the Meta XR Simulator. It allows you to control the headset and controllers to aid in development and debugging.

Simulator Window Not Showing?

Make sure in EditProject Settings..., scroll down and click on the XR Plugin Management section. You should see three tabs, signifying Desktop, Server, and Android. Under the Desktop tab, make sure Oculus is checked. Then try running the project again.

In the upper left is the Instruction panel, which has a list of controls.

Movement: You can right-click and drag inside the CompositedLayers window to look around, or use the arrow keys on your keyboard. You can use the W A S D keys to move forward, left, back, and right, respectively. You may notice how the view gets tilted after looking around! Use the Q and E keys to tilt the view.

Controllers: The other thing you might want to do is control the controllers separately from the headset. To do so, use the [ and ] keys to cycle through the headset, left controller, and right controller. Then you can use the mouse and WASD keys to control just that device.

Exit: To exit the simulator, you can go to SessionExit Session, then click on Exit Session in the popup. Alternatively, you can go back to the Unity Editor and end play mode by clicking on the play button at the top.

Try pointing a controller to the button and then click the left mouse button to activate it. Do the elevator doors open and close?


Part 3: Building the World

Now, it's time to flesh out the world! Typically, video games have 3D modelers, texture artists, and graphic designers to create assets for the game. While you are very welcome to create your own assets, learning the skills to do so are outside the scope of this course.

Fortunately, there are many free assets available in the Unity Asset Store! Generally, assets from the Unity Asset Store are ready-to-go without much hassle.

Sometimes, the asset store doesn't have what you want. There are many online sources for free assets. Here are two I recommend, but check the resources page for more:

  • Poly.pizza (recommended for 3D models)
  • Pixabay (attribution-free images, music, sounds)

Licensing and Attribution

When you use assets created by other people, make sure to check their license agreement! Oftentimes, they will let you use their work for free, provided that you give them attribution and use it for non-profit purposes. Sometimes, you can even use their work in commercial products! Make sure to check!

Many assets in the Unity Asset Store fall under the "Standard Unity Asset Store EULA", which means you can use it in commercial products AND you don't need to include attribution. This makes it super-convenient to use!

Your Goal

Your goal is to build a world for the user to step out of the elevator and experience. You may want a fantasy world, or a city, the Wild West, or even space! You don't need to have the elevator and plank be in the air, feel free to leave it on the ground if it better showcases your world.

To create your world, try to find assets that fit the theme, import them into your project, and use them to build your scene. I'll show you how to get 3D models from the Unity Asset Store and Poly.pizza.

Other Sources

You are free to use other sources for assets. However, they may not be as easy to import into Unity, and you are on your own for support. See the Unity documentation for help importing models.

âž¡ For this lab, you must include at least three unique 3D models.

Unity Asset Store

Visit the Unity Asset Store and log in with the account you used to set up Unity. Go to the 3D section of the store using the menu at the top. Alternatively, if you know what you want, you can use the search bar.

On the right, under Pricing, check the Free Assets box. This will filter to show only free assets.

Find an asset you like, then click the Add to My Assets button. After accepting the license agreement, it should add it to your account. You can then click the Open in Unity button to open it in the Package Manager, where you can download and import it into your project. You can see all the assets you've "purchased" in your My Assets page.

Once you've imported an asset from the Package Manager, you should be able to find it somewhere in your Assets folder. I recommend taking note of the directory structure when you import it.

Typically, you will find prefabs of any 3D models. These are the best, and you should be able to drag and drop them from the Project View right into your Hierarchy or Scene. Make sure to adjust the position, rotation, and size to position the asset exactly where you want.

Poly.pizza

Visit the Poly.pizza main site. From here, browse and search for whatever model you think would fit your scene. Once you've found your model, click on it to open it's description page. Click on the download link, then in the menu, select a supported file format: Unity supports FBX (preferred), 3DS, and OBJ files.

Once you've downloaded your model, it's time to import it into Unity. I recommend you make a folder called Models in your project's Assets folder to keep everything organized. Even better, inside your Models folder, have subfolders for each model (because a model can have multiple files!).

If a model is downloaded in a zip file, it likely consists of the model AND supporting materials/textures. You will need to extract the zip file before importing.

To import a model, first open the destination in the Project View. Then, drag and drop all the files you downloaded for that model into the folder. You can also right-click a destination in the Project View and select the Import New Asset... option.

If you select the model in the Project View, you can see its import settings in the Inspector. If your model looks weird, you may want to play with these settings. See the Unity Documentation for more details. The most common option to set is the Scale Factor. Some models are 100x larger due to a difference in unit size. Thus, you would need to set those models' scale factor to 0.01 so you don't have to set the size every single time you use it in your scene.

Textures Not Showing?

If your textures/materials aren't showing properly, it may be an issue with the import settings. Occasionally, the textures may be in separate files. Try following the video here to see how to create and apply materials using textures.


Part 4: (Optional) Testing on the Headset

When you are satisfied with your scene, you can test it on the headset! Each headset comes with a USB-C to USB-C cable. If you do not have a USB-C port on your computer, there should be an adapter in the box. PLEASE DO NOT LOSE THESE! Use the cable (and adapter) to connect the headset to your computer.

Put on the headset. You should see an acknowledgement of some kind asking you if you would like to allow USB debugging. Go ahead and click Allow (or "Always allow from this computer").

Now, in Unity, go to the Oculus menu at the top. Go to OVR BuildOVR Scene Quick Preview. In the dialog that appears, click Build and Deploy APK. This may take a while, but it will build your application for testing on the headset. Once it is deployed, you can unplug the headset and walk around.


Submission

Submit a screenshot of your Unity project open in the editor, with the Scene View showing what your scene looks like outside of the elevator (see example below). As a reminder, you must include at least three unique 3D models. These must be visible in your screenshot! If you need to, you may maximize the Scene View by right-clicking on the Scene tab and selecting Maximize.