[This post on Unity Addressables Benefits was originally posted with its original formatting at The Gamedev Guru's Blog]
If you've been following me, you will probably know my interest in Unity Addressables. That is for a reason.
Unity Addressables is a powerful Unity package that upgrades the way you and I have been tackling some of the most important challenges in Game Development: efficient, pain-free content management.
When managing your game assets, it's hard to keep good standards that prevent our project from becoming a disgusting pile of mess. A big issue there is the coupling between the different responsibilities of our asset management systems.
The way we store the assets in our project has way too much to do with the method we load them, and later use them.
For instance, you may decide to store an innocent sprite in the Resources folder. This, in turn, will force Unity to build the player in a way that that sprite is put into special archive files. And the fact that it was put there, will corner you into loading it through the Resources API.
Things get messy quicker than you can realize!
One choice, multiple long-term consequences.
A good system will prevent you and me from easily making sloppy mistakes like that. A great system will be that, and also easy to learn and use.
With Unity Addressables, we separate the asset management concerns. Our goal is to remain flexible and to keep our project maintainable.
Here are 3 proven ways Unity Addressables will help you and your games:
1. Reduce Your Game's Memory Pressure
When you publish your game, you'll be required on most platforms to specify the minimum hardware specifications your players must meet to buy and play your game.
The math is easy here: the more hardware power you demand, the fewer will buy your game. Or, seen from another perspective, the better memory management you do, the higher the amount of content and fun you can offer in your game.
Unity Addressables helps you in this regard enormously!
To give you a brief idea, converting this kind of code:
public class CharacterCustomization : MonoBehaviour
{
[SerializeField] private List<Material> _armorVariations;
[SerializeField] private MeshRenderer _armorRenderer;
public void ChangeArmorVariation(int variationId)
{
_armorRenderer.material = _armorVariations[variationId];
}
}
Into this other one:
using UnityEngine.AddressableAssets;
public class CharacterCustomizationV2 : MonoBehaviour
{
[SerializeField] private List<AssetReference> _armorVariations;
[SerializeField] private MeshRenderer _armorRenderer;
public IEnumerator ChangeArmorVariation(int variationId)
{
var loadProcess = _armorVariations[variationId].LoadAssetAsync();
yield return loadProcess;
_armorRenderer.material = loadProcess.Result;
}
}
Will bring you these results:
Easy gains I'd say.
-> Read more on Unity Addressables for better memory management in Unity Addressables: It's Never Too Big to Fit (opens in a new tab)
2. Sell Your Next DLC - Quick and Easy
The fact that Addessables gives you full control over how, when and where to store and load your game assets is incredibly useful for implementing and selling Downloadable Content.
Even if you are not thinking of releasing DLCs any time soon, just by using Unity Addressables in your project, you will have done already a big chunk of the work ahead.
Other approaches for selling DLCs, such as Asset Bundles, are a very deprecated way of doing the same thing but at a much higher cost. Maintaining a well-functioning Asset Bundle pipeline is painfully time-consuming and requires a high degree of expensive expertise.
There are many ways you can approach implementing DLCs in Unity, but for starters, this is a good starting point:
public class DlcManager : MonoBehaviour
{
// ...
public IEnumerator TryDownloadDlc()
{
if (_hasBoughtDlc && _dlcDownloaded == false)
{
var operationHandle = Addressables.DownloadDependenciesAsync("DLC-Content");
while (operationHandle.IsDone == false)
{
_progressText.text = $"{operationHandle.PercentComplete * 100.0f} %";
yield return operationHandle;
}
}
}
}
You get the idea.
Why would you say no to selling more entertainment for your players at a fraction of the cost?
3. Reduce Your Iteration Times
Using Unity Addressables will reduce the time wasted waiting in several areas.
Tell me, how frustrating is it to be blocked for half a minute after pressing the Unity play button? And it only gets worse if you deploy your build on another platform, such as mobile or WebGL. This all starts adding minutes and minutes to your iteration times. It gets old so quickly.
I don't like waiting either.
But do you know what I like? Unity Addressables, my long-awaited hero. This is how Addressables will help you:
A) Reduced Build Size
Your game has a lot of content, I get it. Gamers love enjoying content. Developers love creating content.
That doesn't mean, however, that every single asset you produced has to be included in the build your players will install. In fact, you should remove as much as possible.
Players want to start playing ASAP. And they're not happy when your game steals 2GB of their data plan and 30 minutes of their gaming time. They'll just keep downloading Candy Crush kind of games that install well under 50MB.
One strategy is to include only the assets needed to run your game up to the main menu. Then, you can progressively download the rest of your content in the background, starting of course downloading the first level of your game.
It's also neat to realize that your deployment times during development will sink. You'll be able to iterate more times each day; this benefit quickly adds up in the long term.
B) Reduced Load Times
We, both as game developers and as players, hate waiting. Waiting takes us out of the zone and before you realize it, it is time to go to bed.
Unity is working hard towards reducing the time it takes us to start playing our games, both in the Unity Editor and in the games we distribute.
But not hard enough.
Things look promising in the future, but not without side effects. Avoiding domain reloads in Unity 2019.3 looks promising, but as of today that's still in beta and not everyone can profit from it.
In the mean-time, we can do better than just being frustrated.
Let's say you're working on a medieval game. Several months ago, you implemented armor types for your game. You did a pretty damn good job and generated over 100MB of content.
At some point, it was time to move on and right now you're working on something else, let's say sword fighting.
Realize that, every time you press the play button to work on your features, you are loading an insane amount of data coming from all the already developed features, and loading this data takes a massive amount of time. You press play to test your sword fighting animations, and you spend 5 seconds waiting due to loading the armor features you implemented.
The time wasted in loading is mostly spent on I/O (Input/Output), because memory bandwidth is expensive. And, on top of that, your CPU has to process it. You, as a developer, pay this time penalty while developing in the Unity Editor. But your players pay it as well in the games you are distributing.
Knowing how big of a deal this can be, let's ask ourselves: which shortcuts can we take here?
It turns out that Unity Addressables can help us here in two ways.
Addressables will reduce your Players' Loading Times
We can alleviate some of our players' pain.
Keeping indirect references to our assets instead of direct references will drastically improve your loading times.
By using indirect references (AssetReference), Unity will not load everything at once but only what you tell it to. And more importantly, you have direct control over when that happens.
Addressables will reduce your Unity Editor Iteration Times
How much do you know about the play mode script in the Unity Addressables Window? The play mode script defines how the Unity Editor should load the content marked as Addressable.
With Packed Play Mode selected, Unity will directly load your pre-built addressable assets with little to no processing overhead, effectively reducing your Unity Editor iteration times
Just do not forget to build the player content for this to work
What if you applied these strategies to your most demanding content?
4. Extra: Are You There Yet?
It is true. Unity Addressables is very helpful. But this package will help only those who want to be helped.
After reading how Addressables will help you producing better and selling more to your players, you probably want to start with it right away. However, starting in this new unknown area may be challenging.
To make the most of your chance, answer these questions first:
- Where are you standing right now? Are you just starting, or are your skills production-ready?
- When to use indirect references, when to use direct references?
- What's the bigger picture?
- What is your next logical step?
Top comments (0)