Addressable Asset System in Unity

Addressable asset system

Like the real world, Unity used “Address” to find objects in runtime. All the asset management is done by an addressable asset system by providing each asset a specific address.

The addressable asset system is used asynchronous method to load an asset from its location with all its dependency. Yes, you read that right, it loads all the dependency, unlike the old asset Bundle system.

It will provide a variety of advantages over the old system, like optimize iteration time, memory management, dependency management and obviously content packing.

Isn’t it curious? let’s deep dive into the addressable asset system to know how can we manage the asset for best use cases.

How to install an addressable asset system?

  • Create New unity project with 2018.3 or later(Current Version for this demo this 2018.4.8f1)
  • Now go to Windows-> Package Manager and install Addressable from the list(current version 1.5.0)¬†
    Addressable asset system
    Addressable asset system installation
  • ¬†After installation is completed, go to Windows->Asset Management->Addressables->Groups, this will leads to you in following screen.
    Addressable asset group
    Default Addressable asset group
  • Click on the Create Addressable settings button, This will create some files in your project, and mainly resides in the Addressable asset data directory in asset folder.
  • Now you have following default asset group.
    Default asset group
    Default asset group

How to create an Addressable Asset?

Addressable asset creation is easier than you think. You can create by following ways.

  • Now create a cube and make it prefab. Select this cube prefab and mark it as addressable asset like below.
    Marking of addressable asset
    Marking of addressable asset
  • Change the Addressable Asset name to Cube. You can name it anything as you want.
  • This will automatically add this cube into your default asset gruop and looks like the following image.
    Default asset group
    Default asset group

How to build content using an addressable asset system?

After adding all your addressable asset into an asset group, now its time to build the content for your specific platform. Note that every platform needs a new build and you can update content by the platform-specific previous build.

You can create a different asset group by their use. i.e if you have some asset stored locally in the resource folder or any other folder you can add into the one group and if you have remote content then add into another asset group.

You can specify any number of asset groups and set this group how they will pack your content. Once you select any asset group, the group-specific settings are shown in the inspector, where you can set the path of your load and build an asset group. This path is based on where you want to deploy your content.

Now set the play mode script based on your requirement. All scripts have different usability. Make sure you read the unity doc first.

Now go to Build -> New build -> Default build script to build your content. This content will build on the “BuildPath” you specified in the asset group.

How to use an addressable asset from the build content?

There are different methods to use this asset from the content. Like you load or instantiate assets by their name, references, and labels.

Here, we want to instantiate the cube prefab using an addressable asset system. So you need to write a script as following to do it.

using UnityEngine;
using UnityEngine.AddressableAssets;

public class Demo : MonoBehaviour
{
    public string cubeName = "Cube";

    private void Start()
    {
        Addressables.InstantiateAsync(cubeName);
    }
}

Attached this script to any gameobject and run the unity. It will instantiate the cube prefab from the content you build before.

In conclusion, we can say that the addressable asset system will provide an easier way to manage content and its dependancy just by their address. You don’t need to handle all these things like before. We can see how we can use remote content with this system in an upcoming post.

Leave a Reply