11th May 2021

Getting started with Addressables in Unity

Game Development

Written By, Bhavesh Kadchha

Overview

An asset is a content that we use to create our game and building assets is important in the game development process. Examples of an are assets prefabs, textures, materials, audio clips, animations, etc. An AssetBundle is content that is stored separately from the main game and can be loaded (or downloaded) at runtime.

An Addressable is a Unity editor and runtime asset management system that uses the existing AssetBundles system to provide an easy way to create and load assets by using “address”.
It handles asset management workload by making content pack creation and deployment easy. It uses asynchronous loading to load assets by using direct references, unique address traditional AssetBundles, or from “Resource” folders.

In a nutshell, Addressables is an entire content management pipeline, while AssetBundles is simply a way for packing content.

ADVANTAGES OF USING ADDRESSABLE

  • In Addressables content referred by its unique “address” thus making it extremely efficient. This also removes the requirement to change in code for optimizations of the content.
  • It returns all dependencies of the asset bundle so that everything related to that asset is loaded before returning the asset to you.
  • This system provides a robust profiler to help find any potential memory problem by counting the reference automatically and loading and unloading assets depending on references.
  • Packing of bundles is very efficient, even when moving or renaming assets because the system internally maps and understands complex dependency chains. You can easily prepare and deploy downloadable content for both remote and local deployment and reduce the application size.
  • Addressables allow you to create string variables for each asset. This enables you to change how your content is packed without modifying settings in multiple locations.
  • Addressable allows users to edit and change the build and load locations using profiles, has an in-built profiler for overhead calculations and debugging, provides tools for local hosting for testing purposes, etc for easing work for developers.

1. Setting up the development environment

For adding addressables in your project just go to Windows > Package Manager and Install “Addressables”.

2. Marking Assets as Addressables

There are initially two methods on how you can mark an item as an Addressable Asset. You can mark an asset as addressable by clicking on the “Addressable” checkbox and then entering the name to identify the asset.

addrasable-checkbox

Or, we can open the Addressables window by clicking on Window > Asset Management > Addressable > Group and then dragging the item from the Project window into a group in the Addressable window’s Asset table.

addresable-grp

When you mark an asset as an Addressable the default “address” for that asset will be the path of the asset in your project. You can change the address to any unique name by editing string in the Addressable Name variable in the Addressable Group tab for any Addressable asset.

3. Creating Addressable Groups

When you mark something as Addressable, it becomes a part of the Addressable Group. Each group has its own setting and determines how your content will be built into a bundle. It also has some useful settings like Build Path and Load Path.

You can create a profile for Addressable Group and then tweak the variables as per your requirement for that particular Addressable Group.

To create a new Addressable Group, In the Addressable Groups Window, Click on Create > Group and select the type of Group you want to create.

Addressable Group’s Properties

append-group

Addressable Groups use a scriptable pipeline to store all the settings and properties for a particular Addressable group. Here is a brief description of a few important properties :

You can change where the Addressable assets will be built by changing the profile or editing the variable of the currently active profile. Then you need to assign the variable into “Build Path” and “Load Path” in the Addressable group setting. The Addressable group will be built as per the setting. So you can manage the remote and local building and loading assets using variables in the Addressable Profiles.

Content update restrictions

Content update workflow intended for games that will dynamically be downloaded from a remote server. There are two recommended structures for this.

  1. Can Change Post Release: This option is used on content that you wish to keep dynamic and update in the future. Content marked by this option will be shipped with the application or will be downloaded soon after install.
  2. Cannot Change Post Release: This option is used for content that you never expect to update. Content marked with this option resides online, mostly in smaller bundles to minimize the data required to update.

Bundle Mode

You can Pack the bundles in three different manners as per your requirement in the project.

  • Pack Together: Every asset in the Addressable group will be bundled and loaded together.
  • Pack Separately: Every asset in Addressable Group will be its own asset bundle. That means you can load the individual Asset without loading others in the same Group.
  • Pack Together by Label: All the assets in Addressable Group that share a Label will be bundled and loaded together.

Packing together more bundles will make the size of the project smaller, but patching the project will become complicated. Packing Separately will make the project size bigger than Packing Together, but it will make the project patching easier.

 4. Configuring Addressable profiles

Addressable profiles allow you to create a set of strings that will define where your content is built and loaded from. These variables will define if your content is built on a local or remote server. You can edit and add variables in the profile to define build and load paths.

You can also create multiple profiles so that you don’t need to change the variables of a profile every time you need to change the build and load locations. You can “Set Active” a profile, “Rename Profile” or “Delete Profile” by right-clicking on the profile.

5. Adding labels for internal grouping

Adding labels

You can also provide an additional Identifier to the assets called Label.

You can have multiple labels assigned to a single Asset too.

adding-labels

Understanding MergeModes

While Loading Addressable you can sort the Addressable using MergeMode. These are the types of MergeMode that are available.

  • UseFirst & UseNone load assets containing the first label in the collection.
  • Union will provide all the assets having any provided Label.
  • Intersection loads all the assets that contain the exact labels that are provided.

6. Building Addressables Bundles

To build your assets go to the Addressable Groups Window and click on Build Then you can build a new build using “New Build” option. You can also use “Update a Previous Build” if you want to update a previous build.

7. Retrieving Assets from Addressable Asset Bundles

You can load and instantiate Asset runtime. Loading an asset will load all dependencies including AssetBundle(if Relevant) into the memory. After loading you can use the asset whenever you need to in the project runtime.

NOTE: “UnityEngine.AddressableAssets” namespace is required for working with Addressables and “UnityEngine.ResourceManagement.AsyncOperations” namespace is required for doing asynchronous operations.

Using an AssetReference

AssetReference is a simple introduction to using Addressables. They use AssetBundle behind the scenes to make loading, downloading, and updating content efficient for developers. AssetReference holds a reference to an Addressable Asset for Load and Instantiate the asset just like you have a single object reference.

You can Load assets by using its “AssetReference”. Example of loading an asset runtime using AssetReference :

You can Instantiate assets by using its “AssetReference”. Example of instantiating an asset runtime using AssetReference :

LoadAsset() will load the asset so that you can use it later while Instantiate() method loads the Asset and adds it into the scene immediately. LoadAsset() and Instantiate() methods, both are async operations. That means you need to provide a callback that will work after the asset has been loaded.

Using an address:

You can Load assets by using its “address”. Example of loading an Asset runtime:

You can Instantiate assets by using its “address”. Example of Instantiate an Asset runtime:

Using a label

Labels are helpful for run-time loading for similar assets or a similar group of assets.

For example, If an Addressable group named “Prefabs” contains all the prefabs, you can label “Enemy” to Enemy prefabs and simply call this LoadAll(“Enemy”); to load all the “Enemy” prefabs.

You can use MergeModes explained in a previous section to leverage labels

Conclusion

Addressable reduces lots of manual labor and chances of error out of the conventional methods of AssetBundling and handling Assets. It is very powerful and flexible. It separates code and Asset development paths and unifies the remote and local content. The utilities of Addressables are wide-ranging and rare and are very beneficial for lots of projects in unity.

Written By,

Game Developer at Yudiz Solutions Pvt. Ltd