On this page
How to set up video in Unity (including 360 and VR): It’s easier than you might thinkLast updated: January 2019
What you will get from this page: Steps for how to place video in your scenes with the Video Player Component. The Video Player supports 4k, 8k and higher video across platforms, including mobile. You can include 360-degree video in both 3D and VR games and interactive content.
How to set up video in Unity
Getting your video into Unity starts with importing a Video Clip and then configuring it using the Video Player Component. H.264 (typically in a .mp4, .m4v or .mov format) is the optimal supported video codec because it offers the best compatibility across platforms.
When you select a Video Clip, the Inspector shows the Video Clip Importer, including video-specific options, preview, and source details. Settings include options to flip the video horizontally or vertically, and adapt the transcode process for each targeted platform. You can click the Play button at the top-right of the preview to play the Video Clip, along with its first audio track (see screenshot below).
A Video Clip Asset viewed in the the Inspector window, showing the Video Clip Importer options.
The Video Player Component
You use the Video Player Component to attach video files to GameObjects, and play them on the GameObject’s Texture at runtime.
By default, the Material Property of a Video Player Component is set to _MainTex, which means that when the Video Player component is attached to a GameObject that has a Renderer, it automatically assigns itself to the Texture on that Renderer (because this is the main Texture for the GameObject).
A Video Player component attached to a spherical GameObject, playing the Video Clip on the GameObject’s main Texture (in this case, the Texture of the Mesh Renderer).
The Video Player Component has a number of properties that give you a lot of flexibility for how to display, while Audio Output Mode lets you manage the audio for your video. For example, if you set it to Audio Source you can use the Audio Mixer to to easily tweak sound.
Render modes for your Video Player
One of the powerful properties you’ll definitely want to experiment with is Render Mode.
Render Mode enables you to display your video in interesting ways, including:
- Camera far plane: render the video behind everything in your game.
- Camera near plane: render the video in front of everything in your game.
- Render texture: to render the video as an image effect, on your UI, and so on.
- Material Override: this enables you to render the video into a selected Texture property of a GameObject through its Renderer’s Material. It’s a great option for doing special effects with your video, such as rendering it as a hologram (by inputting the video into a hologram shader), or curving it around the outside of a mesh. When you choose Material Override, you’ll get an additional drop-down field to fill in a Renderer, such as a Mesh, Skin, Particle Renderer, and so on.
Take it to the next level with 360 video rendering in Unity
360 video is straight-forward to do with the Video Player; essentially what it does, is output a texture which then wraps and is used as 360 video. And the steps to set it up are similar to non-360 video, take a look:
- You can use any supported video file that contains either 360 or 180 equirectangular or cubemap content.
- Import it as a Video Clip Asset, and play it through a Video Player Component.
- Important: Target the Video Player to a Render Texture of the same dimensions as the video. Then, connect that texture to a Material that’s set to use the new Skybox/Panoramic shader (currently in beta), and use that as your Scene Skybox Material.
Voila! Your Skybox should now be driven by your panoramic video.
And for VR?
Just turn on the Virtual Reality Support Player Setting, put on a VR headset, and you’ll immediately be surrounded by your video in full 360.
A few more handy tips and tricks
Unity senior evangelist Andy Touch demos a number of cool tips in this Unite session, including:
Pixel Sampling (at 21:20): Andy gives some tips on how to adjust the lighting in your scene so that it realistically reflects the brightness and colors coming from a video.
Rendering to Unity UI (at 25:08): Unity UI does not have a renderer that you can directly plug video into. Instead, it has its own camera settings, image settings, and a different way of batching and rendering UI elements. One trick you can do is to render a render texture into the UI element that you want the video to play on.