While Unity is a game engine and designed for making video games, it’s use cases go much further than that. You can use Unity to create a standalone executable that plays your 360° masterpiece or a Bandersnatch style choose-your-own 360° adventure.
Preparing the 360° Video
Unity is resolution agnostic meaning it can accept whatever obscure video resolution you throw at it. That said, just because it can accept it does not mean it will look good. For this guide we are using 2:1 equirectangular footage as that works best but you could also use a cubemap projection or an over/under stereoscopic projection with some minor modifications.
It’s also important to keep in mind that higher resolutions are more CPU intensive on a computer that is already driving a VR rig. You should choose an export resolution that is matched with your hardware. For example, an HTC Vive can’t show 8K video so it would be a better use of resources to downscale 8K footage to 5K.
- Encoding: H.264
- Format: .mp4
- Resolution: 3840 x 1920
Creating a Unity Video Player Scene
With your video prepared you’ll just need to create a new Unity scene to contain it in. This guide assumes that you’ve just opened a brand new Unity project.
- Import your 360° by selecting Assets → Import New Asset… from the menu bar and navigating to your video file.
Create a new Render Texture by selecting Assets → Create → Render Texture from the menu bar.
- A render texture is a special type of texture that updates at runtime and in our case will server as a destination for the video as it plays.
- Rename the Render Texture to something that identifies it, I chose “360 Render Texture.”
- Select the 360 Render Texture and in the Inspector panel, change it’s resolution to match your video’s resolution.
- Create a new Material by selecting Assets → Create → Material from the menu bar.
- Materials define how a surface will be rendered based on the textures assigned to it. It will use the 360 Render Texture in this case.
- Select Window → Rendering → Lighting Settings from the menu bar.
- Replace the “Default-Skybox” by dragging the 360 Material from the Project panel into the “Skybox Material” property.
- This makes the 360 video act as the all encompassing environment of the scene.
- Create a new Game Object by selecting GameObject → Create Empty from the menu bar.
- In the Hierarchy panel, rename the newly created GameObject to something that identifies it, I chose “360 Game Object.”
- With the 360 Game Object selected, choose Component → Video → Video Player from the menu bar.
- In the Inspector panel, drag the video footage from the Project panel into the “Video Clip” property and the 360 Render Texture into the “Target Texture” property.
- This caused the render texture to server as the “screen” for the video within the scene.
At this point the video is now the environment which surrounds your scene. You could stop here if you are trying to use your footage as a custom skybox, or you can continue to create a fully realized VR player.
Putting a 360° Scene into VR
With the scene set up with a 360° environment, it is not too difficult to transform it into a VR scene.
- From the Asset store panel, search for, download, and import the “SteamVR Plugin” offered by Valve Corporation. It will take some time to download and subsequently import.
- SteamVR as a tendency to throw popups about calibration settings. Choose “Accept All” should it pop-up.
- SteamVR will have added itself as a folder in the Project panel. Inside that folder navigate to “Prefabs” and drag “[Camera Rig]” into the Hierarchy panel.
- In the Hierarchy panel remove the “Main Camera” asset.
- The first time you hit play with SteamVR in the scene it will ask to create input bindings, select “Yes” and “Save and Generate.”
You now have a VR-ready 360° video player.
Building the VR 360° Video Player
In Unity, building is the process of compiling assets into a standalone executable file. We’re going to do this to make a standalone 360° Video Player application.
- Save the scene by selecting File → Save from the menu bar.
- Open the Build Settings by selecting File → Build Settings from the menu bar.
- In the resulting window, choose “Add Open Scenes.”
- The “Player Settings” will allow you to change the application’s name, icon, author and other metadata.
- Ensure the “Target Platform” is Windows as our VR systems only run Windows.
- Click “Build” and choose where you want to save your build, preferably in a new empty folder.
You now have a completed standalone executable which contains your video. Note that Windows builds include a sidecar folder called “Data” and several accessory files so it is best to move it within the containing folder to other devices.
From this project you could build a UI interface inside Unity, add interactable objects, etc. The possibilities are endless.