156 syllabus      site index      3D artists      past student work        DMA

A Unity Primitives with VR

Basic VR with Unity primitives SteamVR and HTC Vive

Start Unity Hub
(You may need to set up an account)

Make sure you are using Unity 2019.4.11f1
Go to Installs

Go to Projects
Select New, hold down the unity_down_arrow_hierarchy arrow to select 2019.4.11f1
     Project Name 
Give your project a name such as A_Primitive_Tutorial.
          This will create a folder with folders inside.
     Location  Save to the Desktop or your external drive.
     Select 3D.
     Select CREATE
     Select Allow access to the Firewall pop-up, if it appears.

Make sure the main view is the
Scene tab.

Add some primitives
The nice thing about primitives is the collision boundaries are already set up.

Choose GameObject->3D Object->Cube etc. We will use the cube for the floor

Hand moves the view, Move Tool, Rotate Tool, Scale Tool, Rectangle Select,and the 'Move Rotate Scale' Tool.

Select the cube to be used for the floor.
Look at the Inspector tab on the right, Scale should be around 15, .1, 15 x,y,z for the floor cube. (You might need to switch from Services to Inspector.)
Set Position to 0, -.05, 0
You can re-name the floor in the Inspector tab.
Set Cast Shadows to Off in the Inspector.

Add more primitive shapes, place them above the floor.

Add some materials
Select Assets->Create->Material.
Double click the material in Assets below.
Change the Albedo color in the Inspector on the right.
Drag and drop the material onto the primitive while in Scene Mode

Scene View Camera
Use the Alt key left mouse to tumble the camera. Alt right mouse to zoom.

Click an axis such as X in with the XYZ axis to look down the X axis.
You can toggle between
Persp, Iso and 2D by clicking on the word below the axis.

F for Frame
Select an object, hit f
The camera will adjust the clipping planes and zoom in on the object.
You may notice some objects gradually disappearing, use f to adjust this.

Import plugin
, Steam VR Camera and Controllers for VR
Choose the Asset Store tab next to the Scene window tab
If the Asset Store says you are offline, sign out and then back in to your Unity account

Type SteamVR in the search bar
Select the
SteamVR Plugin by Valve  (It is free)
If you have never done this select Download first, then Import

Choose Import
in the store window

The Import Unity package window will pop-up
   Scroll down to Longbow
       Uncheck Longbow
   Scroll down to Samples
       Uncheck Samples
Select Import
Accept All if there is a SteamVR error messages about Resizeable Window.

Plugins always import into the Assets folder of your project. You can always copy or delete the SteamVR folders between projects.

Put the main view window back to Scene instead of Asset Store

Select the SteamVR folder from the Project tab
Select the arrowunity_down_arrow_hierarchy, open InteractionSystemunity_down_arrow_hierarchy, open Coreunity_down_arrow_hierarchy, select Prefabs
Drag the Player into the Hierarchy tab


SteamVR Camera Settings
Simulation Camera:
Open the arrow next to Player in the Hierarchy unity_down_arrow_hierarchy
     Open the arrow next to NoSteamVRFallbackObjects unity_down_arrow_hierarchy
     Select FallbackObjects
          Change Position in Y to 0
          Change Field of View to 90  (default 60)

Grab and drop the
Game tab below the Scene tab to create a split view.

Player from the Hierarchy to position and rotate the SteamVR camera. You will see the result in the Game tab

Setup the Main Camera to be out of the way
Select the Main Camera from the Hierarchy tab
In the Inspector tab:
     Uncheck Audio Listener
Change Target Display to Display 2

     Change Target Eye to None in the Inspector tab
(The main camera interferes with SteamVR.)

Try your Project in Sim mode.

Hit the Play button to stop and start your game.   unity_play_arrow

If you are running in
Sim mode use w a s d, q r or the arrow buttons to navigate around the scene, and the right mouse to rotate the camera. Left mouse for interactions.

Throwable Objects
This tool came with SteamVR.
Create a cube, GameObject->3D Object->Cube

Select the cube, use Add Component button located in the inspector at the bottom.
     search for throw
select Throwable

Under Interactable Script in the Inspector
     Turn off Highlight on Hover

Hit Play and throw your object, view this in the Game tab.

Add Velocity
Select the cube, use Add Component
     search for vel select VelocityEstimator

Hit Play

Add a Physics Material to make the objects bouncy
Select the Assets->Create->Physic Material from the menu.
Give the material a name.
Select the Physic Material
Change Bounciness to .4 in the Inspector

Select the object you would like to adjust the bounciness:
     In the Inspector tab
, under Collider, assign the Material


Hit Play,
try adjusting the bounciness.

Import a new Skybox
Choose the
Asset Store tab next to the Scene window

     Type skybox in the search bar, Select Free Assets
Download and Import

Put the main view window back to Scene

Choose Window->Rendering->Lighting Settings
Click the unity_dot to c
hange the Skybox Material to the skybox you imported.
You can also make your own.

Solid Color Background if you do not want to use a Skybox
Main Camera:

Window->Rendering->Lighting Settings
Click the unity_dot next to Skybox Material select None

Scene Window and Unity interface:
Select Edit->Preferences   (Mac: Select Unity->Preferences)
     Select Colors
          Change the Background color

SteamVR Headset Camera:
Open the arrow next to Player in the Hierarchy unity_down_arrow_hierarchy
     Open the arrow next to SteamVRObjects unity_down_arrow_hierarchy
     Select VRCamera
     Under Clear Flags change Skybox to Solid Color in the Inspector
     Change the Background color in the Inspector
     Change the Field of View to 90

Simulation Camera:
Open the arrow next to Player in the Hierarchy unity_down_arrow_hierarchy
     Open the arrow next to NoSteamVRFallbackObjects unity_down_arrow_hierarchy
     Select FallbackObjects
     Under Clear Flags change Skybox to Solid Color in the Inspector
     Change the Background color in the Inspector

Fix the shadows
All these settings can slow down performance.
Select Edit->Project Settings
          Uncheck all Levels
except Ultra
     Change Shadow Resolution to Very High Resolution
     If the shadow does not appear when you make a Player
Shadow distance to 40     (default 150)

Select your Directional Light
     Lower the Strength
to make the shadows lighter, try .5   (default 1)
     Change Bias
to .007             this will be more precise (default .05)
     Keep Normal Bias to .4       (default .4)
     Change Near Plane to .1      ( default .2)

Go to Publish WebGL
Go here to publish your project to webGL.





If the Vive VR is not working with the headset
Start Steam steam_VR1 
First time use, Steam will ask you to login, you may set up an account or use the department's account: login dmaucla password UCLAdma!
This login seems to hang. It should work OK if you try restarting your Unity project. Worse case reboot the computer.

Make sure the headset and controllers are connected
Try wiggling the Headset.
Try pressing both the round buttons on the controllers together.
Make sure the hand held controllers are charged.
Steam Status Utility will look like this if it is ready.

Reset Steam if you don't see all the icons
     Select the down arrow next to SteamVR unity_steam_arrow
     Select Devices->Reboot Vive headset
     There is also a menu to Run Room Setup, this should be done already

How to transfer Your Project Between Mac and PC
Move the entire project over to the PC or Mac, keep a backup
Open Unity Hub
Under Projects, select ADD
Select your folder

Start the project from the list of Projects
If it asks you to Switch Target upgrade or downgrade  you must answer CONFIRM
If the versions are close enough it should work.)

A message window from SteamVR may pop up:

It looks like you haven't generated actions for SteamVR Input yet.
Would you like to open the SteamVR Input window?
    Answer Yes


Make a stand alone Player
Follow this section on a PC
You will be recording the project while looking through a Vive headset on a PC.

Build your project to run on it's own without Unity

File->Save Scene your scene

File Build Settings...
Uncheck Scenes/SampleScene if you see it
PC, Mac & Linux stand-alone
Build & Run
          Select your Target Platform such as Windows
          Select Build And Run
               Create a folder
outside of your Unity project
               Save to the folder...   wait a second

Alt F4 exits the player on a PC
Command Q exits the player on a Mac
(A stand alone player made on a Mac will not play on a PC.)

OBS screen capture VR documentation