smallarrows.GIF
titlebar_image

Unity SteamVR Setup, Build from Scratch

Prebuilt SteamVR Project with Universal Rendering Pipeline
Download this 2021 scene, move the folder to your Desktop or working area.
This file is already setup with SteamVR and some other tools.
https://classes.dma.ucla.edu/Fall22/156/projects/URPtemplate.zip



Build Your Own Project from Scratch
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Unity Hub
Projects Section
     Select
New project
          Select 3D URP, Download template
          Name the project and choose a location for the new folder

The project should take a while to open.


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Import SteamVR plugin
Steam VR is a package that controls the VR Camera and Controllers for Valve Vive headsets.
This package also installs an XR Plug-in called OpenVR Loader or OpenVR XR Plugin.

Use Window->Asset Store
     Choose Search online
          Sign in with your Unity ID
     Search for SteamVR
          Choose the one from Valve Corporation  2.7.3
     Select Open in Unity

Select Window->Package Manager
     Packages: My Assets should be selected
     Click
Sign in
          A browser window will open to open the Unity Hub
          Go back to the Package Manager
               Select Load All (so you can see SteamVR)
     Choose
SteamVR Plugin
     Choose Import
You may want to deselect a few option to make the file size smaller:
     Deselect Longbow, and collapse the arrow
     Deselect Samples
    Select Samples Scripts
     Import

(You can always install these later, you may want to try the Interactions_Example file from Samples.)

Close the Package Manager

Message window from SteamVR:
Run In Background, Use recommended (True),
     Choose Accept All


Import SteamVR plugin from Github
Download and import SteamVR github
v2.7.3
     Scroll down the page to select steamvr_2_7_3.unitypackage
     Place the file in your
Assets folder and double click to install




Unity on Mac computers does not recognize OpenVR
Ignore all the error messages and switch platform if asked
Select
Window->Package Manager
     Packages: In Project
          Select OpenVR XR plugin and Remove


Add a Player Camera
Select the
Scene tab

Locate Assets\SteamVR\Interaction System\Core\Prefabs\Player
Drag the Player into the Hierarchy tab

Unity_steam_primitives1



SteamVR Camera Settings
Simulation Camera:
Open the arrow next to Player in the Hierarchy unity_down_arrow_hierarchy
     Open NoSteamVRFallbackObjects
          Select FallbackObjects
               Change Position in Y to 0
     Change Anti-aliasing Fast Approximate Anto-Aliasing (FXAA)   (default No Anto-aliasing)


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



Delete the Main Camera to be out of the way
Select the Main Camera from the Hierarchy tab
Delete
it



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Add a Collider to your SteamVR simulator Camera
Here are some tools to augment the SteamVR plugin written for you by Alex Rickett, UCLA Game lab
This tool is written to augment the Unity Steam simulator, this adds collisions to the Player camera. The camera will stop at any object such as a wall that has a collider.

Download this file
HelperCollider_v3.unitypackage
    On a PC right mouse Extract All...
BUG On a Mac the file might automatically unzip, if not use Stuffit to unzip. You know there is a problem if you do not see one file called
HelperCollider_v3.unitypackage.  It should look like this: helpercollider_mac
You can set Safari to not unzip: Safari->Preferences->General, uncheck Open "Safe" Files


Drag and drop the HelperCollider_v3.unitypackage into your project Assets folder.
     Install the package, double click and select 
Import
     This adds a folder called
HelperLibrary into the project, there is a prefab and and script.

Open the
HelperLibrary folder in Assets.
Drag the
SteamVRSimulatorColliderHelper prefab into your project Hierarchy, (not as a child of the Player)

Make sure the Player's Body Collider and the HeadCollider are part of the Default Layer.

Helper_collider_pic

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
You won't see this while running the simulator, you need a VR headset
Teleportation
Drag the Assets/SteamVR/Teleport/Prefabs/Teleporting into your Hierarchy.

Place a plane just above the ground, it can not be below.

Add Component->Teleport Area


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
You won't see this while running the simulator
Hide the Glove, Replace with a controller
Select Assets/SteamVR/InteractionSystem/.Core/Prefabs/LeftRenderModel Slim
     Uncheck Display Hand By Default
     Select Display Controller By Default


Change the Glove Color of the VR Hands
You may want to update all the Pink SteamVR materials to URP
Select Assets/SteamVR/Models/Materials

Select any pink materials
     Run
Edit->Rendering->Materials->Convert Selected Built-in Materials to URP


Select Assets/SteamVR/Models/Materials/vr_glove_color_red
Three dot menu near top select Reset




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Make a new SkyBox
Select Assets-Create->Material
In the Inspector change the Shader to Skybox/Procedural
Play with the color settings

Lighting Settings
Select Window->Rendering->Lighting
     Under the Environment tab, change the Skybox Material to your new SkyBox



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

Choose
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 Shadows and Lighting
These settings can effect performance.

Quality
Edit->Project Settings...
     Select Quality
          Locate Render Pipeline Asset URP-HighFidelity (Universal Render Pipeline Asset) (This is the default for URP)
               Right click on URP-HighFidelity
(Universal Render Pipeline Asset)
                    Select Properties...

                         Decrease Max D
istance to
3
0   (default 150)  This what causes low resolution shadows!


Lights
Select your Directional Light

     Turn on Shadows
     Turn down
Strength to lighten the shadow color, try .5    (default 1)


     Change Render Mode to Important  Do this to main lights, if you have a scene with many lights you will need this. (default auto)



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Hide the mouse cursor & add an Escape button
Select the Main Camera or an object
Select the Add Component button in the Inspector
     Scroll down to New script
          Type a name: hide_cursor_escape
          Double click the new C# script in your Assets folder

Replace entire script with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class hide_cursor_escape : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        Cursor.visible = false;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
}


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Reflection Probe for shiny glass and chrome

Select GameObject->Light->Reflection Probe
Change the Position to 0,0,0 in the Inspector
Make sure your objects are within the cube area. Use this editor to adjust. unity_reflection_probe

Change the
Type to Realtime     (default Baked)
Change the
Clear Flags and Background color to match your camera

Increase Smoothness
on Materials to change the reflectivity




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Really great custom WebGL Front Page Package for Unity
This lets you add your own logo and the page publishes larger. Use with caution, need to test more.

https://github.com/greggman/better-unity-webgl-template
You may need to create a Github account first.
Locate Instructions 2020
     Click this unity package link
     Download betterunitytemplate2020.0.1.0.unitypackage
Select Assets->Import Package->Cutom Package...
If you follow the installation instructions, webGL builds will look a lot more sensible, they will fill the whole browser window, give you and editable logo image to obscure the unity logo while loading.

Select File->Build Settings...
Select Player Settings...
  Select Player
Section
     Under Resolution and Presentation
          Select Better2020



Modify the GUI text Overlay
Modify the directions for interaction:


Modify the Message
Edit the script FallbackCameraController  SteamVR->InteractionSystem->Scripts
Carefully replace each line of text between the "" under the  if ( showInstructions ) section at the bottom of the script.


Change the Font
Make a new folder in Assets called Resources
PC: Copy a font from C:\Windows\Fonts into resources
Mac: Copy a font from Macintosh HD/System/Library/Fonts into Resources, look at the name in the assets for spelling
Edit the script FallbackCameraController  SteamVR->InteractionSystem->Scripts
Replace all the text between the { } for if ( showInstructions ) section
Change the fontname to your selected font

GUIStyle myButtonStyle = new GUIStyle();
myButtonStyle.fontSize = 18;
//create a folder in Assets called Resources, put a font in there
Font myFont = (Font)Resources.Load("fontname", typeof(Font));
myButtonStyle.font = myFont;
myButtonStyle.normal.textColor = Color.white;
myButtonStyle.hover.textColor = Color.white;
GUI.Label(new Rect(5.0f, 5.0f, 600.0f, 400.0f),
"WASD EQ/Arrow Keys to translate the camera\n" +
"Right mouse click to rotate the camera\n" +
"Left mouse click for standard interactions.\n", myButtonStyle);



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Publish to WebGL
You may view your project in a browser on a computer or a phone.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Reinstall OpenVR XR Plugin to run a VR Headset if needed
This plugin interferes with WebGL publish and the Mac simulator.

Select File->Build Settings...
     Select Windows, Mac, Linux
    
Select Switch Platform

Download:
OpenVR
Click Latest button to download:   com.valvesoftware.unity.openvr-1.1.4.tgz tarball file
XR Plug-in called OpenVR Loader or OpenVR XR Plugin.
(There is a copy in the main project folder of the template.)

Window->Package Manager
Under the +, upper left
     Select Add package from tarball...
     Locate the com.valvesoftware.unity.openvr-1.1.4.tgz tarball file in your downloads folder
Change to Packages: In Project
     OpenVR XR Plugin was installed

If VR is not running:
Make sure Edit->Project Settings
    XR Plug-in Management
         Initialize XR on Startup is selected
          OpenVR Loader is selected

Fix Bindings, if it is a problem
Delete the Assets/SteamVR_Input folder in your project.
     Answer yes to generate actions, Save and generate, close window   (This will create a folder in Assets called SteamVR_Input)


Make sure the
Player is at 0,0,0



smallarrows.GIF

© 1988-2022 34 years Jennifer Steinkamp