Lesson 63 +10 XP

Addressables & Asset Bundles

Addressables & Asset Bundles

For large games, packing all assets into the initial installation makes the build size huge and increases load times.

Asset Bundles (Legacy)

Asset Bundles are archive files containing assets (models, textures, scenes) that Unity can load at runtime.

  • You must manually package assets, upload them to a server, and write code to download and cache them.
  • Difficult to manage and prone to dependency issues.

Addressable Asset System (Modern)

The Addressable Asset System provides a modern, unified way to load assets by their "address" (a simple string identifier), whether they are stored locally or hosted on a remote server.

Marking Assets as Addressable:

  1. Install the Addressables package.
  2. Select any asset (e.g. a prefab or texture).
  3. In the Inspector, check the Addressable box.
  4. Note the address path (e.g. "Assets/Prefabs/Enemy.prefab").

Loading Addressables in C#:

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

public class Spawner : MonoBehaviour
{
    public string enemyAddress = "Assets/Prefabs/Enemy.prefab";

    void Start()
    {
        // Load asset asynchronously
        Addressables.LoadAssetAsync<GameObject>(enemyAddress).Completed += OnLoaded;
    }

    void OnLoaded(AsyncOperationHandle<GameObject> handle)
    {
        if (handle.Status == AsyncOperationStatus.Succeeded)
        {
            Instantiate(handle.Result);
        }
    }
}

TL;DR

  • Addressables replace legacy Asset Bundles for dynamic resource loading.
  • Check the 'Addressable' box on an asset to assign it a resource address.
  • Use Addressables.LoadAssetAsync to load resources asynchronously.
  • Releases assets when done to free up RAM.