Let's be honest. Videos are crucial elements for high caliber games, but they feed on storage space. They'll milk till the last bit of your players' drives. They'll skyrocket your game installation times by hours. Would you enjoy staring at a progress bar for 12 hours? Your players won't. No problem, Unity Addressables for Videos comes to the rescue.
Unity-Addressables-Videos-Thumbnail
[Find the original post at Unity Addressables Videos]
Who doesn't enjoy action-packed cinematics?
Your SSD.
And even your users, if it means they must wait till the next day to play your game. Especially if that next day is Monday.
Luckily for us, those are good times to add videos in our games. Unity has prepared some surprises for us so we don't have to choose between low installation times or high-quality cinematics anymore.
Let's see how we can apply Unity Addressables for Videos.
Quick Navigation
Unity Addressables Videos: Path to Success
Importing Video Clips Into Unity
Upgrading to Unity Addressables Videos
Tweaking Unity Addressable Video Groups
Addressable Profiles and Uploading Videos for Network Distribution
Why Can Videos Be a Problem?
Videos are heavy regarding storage space.
No surprise here.
Having a long cinematic with high bitrate and 4k resolution can very well add 350MB per minute. Stacking multiple of those will give you gigabytes of pain.
It is not uncommon to see 100GB+ games nowadays. And videos take a significant portion of that pie.
The thing is, downloading a game as heavy as that takes many hours. And that's not necessarily the problem. The issue is when you block user progression due to huge download times.
But it doesn't have to be that way.
You see, you don't have to force users to wait to download all videos. You don't need them all to show your main menu, right? You play most of them at later stages of the game.
So it helps to split video into two categories: primary and ​secondary videos.
The primary or mandatory videos are those for which users must wait before proceeding in the game. These videos usually come together with the original game package. The game introduction cinematic is an excellent example.
However, you can download the rest of the videos in the background.
The idea is to let the user have some fun instead of forcing them to stare at the progress bar for 12 hours.
We can apply Unity Addressables for Videos to do just this.
Let's see how.
As a side note, Unity Addressables won't help in RAM usage, as videos are played via streaming techniques. You won't make big gains in memory usage but in installation/download times.
The-Gamedev-Guru-Flying-Banner
Unity Addressables Videos: Path to Success
This article assumes you've basic knowledge on Unity Addressables. If you don't, don't risk not understanding a word. I advise you to check my Unity Addressables Tutorial first.
Here's what we will do in this blog post:
Import one primary and one secondary video clips into Unity and play them
Convert the videos to the addressables workflow
Split the videos into two categories: primary and secondary
Upload the secondary videos asset bundles to a CDN for background downloads
Importing Video Clips Into Unity
The first step is to have some videos.
If you have your video pipeline already set up, you can ignore this section. I'll assume you have a video player set up somewhere.
I added two videos I found in the public domain. They're not representative in size, but that doesn't matter. Just replace them with your 4k videos later on.
We will not go on detail here, as there are great tutorials out there.
Basically:
Drop the video files into your Unity project.
In the Unity scene hierarchy, right-click and press Video →Video Player
Tweak your VideoPlayer settings, e.g.:
Set video clip to your video file.
In Render Mode, choose Camera Near Plane
Add a reference to your current camera
That should be it to play a video the classic way.
Import-Unity-Video-Clips
Playing Unity Video Clips
Now we'll step up the game and befriend the Unity Addressables package.
Upgrading to Unity Addressables Videos
The first step is to have the Unity Addressables package installed (you do, right?).
Then, select the videos in your project view and mark them as Addressable in the inspector. Below is a recycled example for audio clips.
Unity-Addressables-Migration-Music-Flag
Now, we cannot play videos as we used to do. We have to get rid of the direct reference to the videos in the video player.
The reason is that the Unity addressables technology works instead with indirect references.
For this we'll create a simple script. If you already have one in place, you can adapt it instead.
The idea is to add an AssetReference field that will point at the video we want to play. We then load the video, assign it to the Unity video player and unload it when it's finished.