Overview
As game development progresses and assets (models, textures, audio, etc.) multiply, several serious problems emerge:
- Increased Memory Usage: Assets placed directly in scenes or referenced by scripts load entirely into memory at scene load and don't automatically release when no longer needed. This causes memory crashes, especially on mobile devices.
- Build Time and Patch Size Growth: All assets bundled in the game inflate build size, requiring users to download large patches for even small updates.
- Difficult Dynamic Content Updates: Adding new characters or stages requires full app updates.
Previously, the Resources folder addressed these issues, but it had many problems: complex memory management and difficult reference tracking. Unity's current official solution is the Addressable Asset System.
Addressables assigns string keys called "addresses" to assets, enabling asynchronous dynamic loading and unloading using those addresses. This separates assets from the main build, loading them into memory only when needed and releasing them immediately when no longer required—enabling highly efficient memory management.
Key Benefits of Addressables
- Optimized Memory Management: Automatically manages asset reference counts, unloading from memory when nothing references them. Frees developers from complex memory management.
- Content Separation and Dynamic Updates: Assets can be separated into "asset bundles" and placed on servers. This enables dynamic content delivery (characters, items, events) without app updates.
- Reduced Build Times: Separating assets from builds shortens initial and daily iteration build times.
Basic Addressables Usage
Step 1: Package Installation and Setup
- Install the
Addressablespackage fromWindow > Package Manager. - After installation, open
Window > Asset Management > Addressables > Groups. Click "Create Addressables Settings" to create configuration files in your project.
Step 2: Making Assets Addressable
Making assets Addressable is simple:
- Select the asset (Prefab, texture, material, etc.) in Project window.
- Check the
Addressablecheckbox in Inspector.
That's it. The asset automatically gets an address matching its file path and is added to Default Local Group. You can manually change the address to any string in Inspector.
Step 3: Loading Assets from Script
Addressables loading is asynchronous—you must wait for completion. Coroutines or async/await are commonly used.
using UnityEngine;
using UnityEngine.AddressableAssets; // Required for Addressables API
using UnityEngine.ResourceManagement.AsyncOperations; // Required for async operations
public class AssetLoader : MonoBehaviour
{
// Address of asset to load
public string assetAddress = "Assets/Prefabs/MyCharacter.prefab";
private GameObject instantiatedObject;
private AsyncOperationHandle<GameObject> loadHandle;
async void Start()
{
// Load asset asynchronously using address
loadHandle = Addressables.LoadAssetAsync<GameObject>(assetAddress);
// Wait for load completion (await)
await loadHandle.Task;
// Check result
if (loadHandle.Status == AsyncOperationStatus.Succeeded)
{
// Instantiate the loaded asset (Prefab in this case)
instantiatedObject = Instantiate(loadHandle.Result);
Debug.Log("Asset loaded and instantiated successfully.");
}
else
{
Debug.LogError("Asset loading failed: " + assetAddress);
}
}
void OnDestroy()
{
// Release loaded asset reference when this component is destroyed
// This tells the Addressables system the asset is no longer needed
if (loadHandle.IsValid())
{
Addressables.Release(loadHandle);
}
// Also destroy instantiated object
if (instantiatedObject != null)
{
Destroy(instantiatedObject);
}
}
}
Addressables.LoadAssetAsync<T>() starts loading, await waits for completion. On success, access the loaded asset via loadHandle.Result.
Most importantly, call Addressables.Release() when assets are no longer needed to release references. Forgetting this keeps assets in memory.
Summary
The Addressable Asset System is foundational technology for scalable asset management in modern Unity development.
- Use Addressables instead of
Resourcesfolder for dynamic asset loading/unloading. - Set assets as
Addressableand manage them with "address" keys. - Load asynchronously from script with
Addressables.LoadAssetAsync<T>(). - Always release references with
Addressables.Release()when done.
It may seem complex initially, but the memory efficiency and content management flexibility from Addressables brings immeasurable benefits, especially for medium to large projects. I strongly recommend getting familiar with this system early.