> For the complete documentation index, see [llms.txt](https://wiki.playgama.com/playgama/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.playgama.com/playgama/guides/performance-and-optimization/unity/addressables.md).

# Addressables

#### Why use Addressables

* Reduce initial download size (recommended: around 10 MB)
* Start the game faster, especially on mobile
* Load only what is needed for the first level
* Download heavy assets later in background

#### Step 1: Install Addressables

1. Open Window → Package Manager
2. Find Addressables
3. Click Install<br>

   <figure><img src="/files/f45v60gbGa1SOX5LyJO3" alt="" width="563"><figcaption></figcaption></figure>

#### Step 2: Create Addressables group

1. Open Window → Asset Management → Addressables → Groups
2. Click New → Packed Assets

Tip: Put related assets in one group (for example, all “Forest level” assets together)

<figure><img src="/files/NqRbV1YreIC1oaYTc7NW" alt=""><figcaption></figcaption></figure>

#### Step 3: Add assets to Addressable groups

* Select the asset you want to make addressable and enable the Addressable checkbox.

![](/files/iwXQXt0tr1y2YLRk7qcO)

![](/files/iwXQXt0tr1y2YLRk7qcO)

* This will add the asset to the default Addressables group and assign it an address (usually based on the file path). You can later modify this address.
* Click the group picker and select the group you created.<br>

  <figure><img src="/files/GOuVbXf3CJUPYvarv74G" alt=""><figcaption></figcaption></figure>

#### Step 4: Load assets from script

Now load Addressables from code instead of loading assets directly.

Use a `[SerializeField]` or public variable so you can drag Addressables into the loader in the Unity Editor.

Example field

```cpp
​​public AssetReference[] backgroundAddressableReferences;
```

And then

```cpp
public void LoadBackgrounds()
{
    List<AsyncOperationHandle<Sprite>> handles = 
        new List<AsyncOperationHandle<Sprite>>();

    foreach (var reference in backgroundAddressableReferences)
    {
        // Check if the reference is valid before loading
        if (reference != null)
        {
            AsyncOperationHandle<Sprite> handle = 
                reference.LoadAssetAsync<GameObject>();

            handle.Completed += OnBackgroundLoaded;
            handles.Add(handle);
        }
    }
}

```

Inside `OnBackgroundLoaded`, use the loaded backgrounds.

```cpp
  private void OnBackgroundLoaded(AsyncOperationHandle<Sprite> handle)
	{
    	if (handle.Status == AsyncOperationStatus.Succeeded)
    	{
        	GameObject Sprite = handle.Result;
        	// Use image here to assign to your in game images
    	}
    	else
    	{
        	Debug.LogError("Failed to load background: " + handle.OperationException);
    	}
	}

```

Later, you can store the loaded Addressables in an array or list and use them when the game needs them.

\*When loading the game, do not load every Addressable at once. Check which assets are needed for the current level and load only that group. Start the game after the required level assets are ready.

<br>
