# Addressables

#### Why use Addressables

* Reduce initial download size (recommended \~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: Include Assets into Addressable Groups

* Click on asset, that you wish to make addressable and check Addressable checkbox on it.

&#x20;                                         ![](/files/iwXQXt0tr1y2YLRk7qcO)

&#x20;                                         ![](/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 on group picker and pick your created group.<br>

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

#### Step 4: Load assets from script

Now you need to load addressables from the script, instead of loading assets directly.&#x20;

You can have \[SerializeField] or public variable, to place / drag and drop addressables directly into loader.

Example field

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

And then&#x20;

```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 function, you can use 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 assets in an array or list and use them when the game needs them.

\*When loading a game, you don’t need to load all addressables, just check which assets are needed for level, and load by level. After loading all needed addressables, in that case, just after loading needed level assets your game will start

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.playgama.com/playgama/performance-and-optimization/unity/addressables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
