# DownloadHandlerAssetBundle

> A DownloadHandler subclass specialized for downloading AssetBundle s.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Networking](/engine/6000.0/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestAssetBundleModule
* **Inherits from:** [DownloadHandler](/engine/6000.0/script-reference/unityengine/networking/downloadhandler.md)
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public sealed class DownloadHandlerAssetBundle : DownloadHandler, IDisposable
```

## Remarks

This subclass streams downloaded data into Unity's AssetBundle decompression and decoding system on worker threads, providing efficient downloading and processing for [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md) objects.

The advantage to this download handler is that it can stream data to Unity's AssetBundle system. After all the data has been received, the AssetBundle is available as an [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md) object. Only one copy of the [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md) object is created. This reduces runtime memory allocation and the memory impact of loading the AssetBundle. It also allows AssetBundles to be partially used while not fully downloaded, so you can stream assets.

All downloading and decompression occurs on worker threads, except on the Web platform.

Downloaded AssetBundle data is processed by a `DownloadHandlerAssetBundle` object, which has a special `assetBundle` property to retrieve the [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md) object.

Due to the way the AssetBundle system works, all AssetBundles must have an address associated with them. Generally, this is the nominal URL at which they're located (meaning the URL before any redirects). In almost all cases, you should pass in the same URL as you passed to the UnityWebRequest. When using the High Level API (HLAPI), this is done for you.

Additional Resources: [UnityWebRequestAssetBundle](/engine/6000.0/script-reference/unityengine/networking/unitywebrequestassetbundle.md)

## Examples

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour {
    void Start() {
        StartCoroutine(GetAssetBundle());
    }

    IEnumerator GetAssetBundle() {
        UnityWebRequest www = new UnityWebRequest("https://www.my-server.com");
        DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(www.url, 0);
        www.downloadHandler = handler;
        yield return www.SendWebRequest();

        if (www.result != UnityWebRequest.Result.Success) {
            Debug.Log(www.error);
        }
        else {
            // Extracts AssetBundle
            AssetBundle bundle = handler.assetBundle;
        }
    }
}
```

## Constructors

| Constructor                                                                                                                                                                                                                                     | Description                                                                        |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [DownloadHandlerAssetBundle(System.String,System.String,UnityEngine.Hash128,System.UInt32)](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/ctor.md#downloadhandlerassetbundle\(string-string-hash128-uint\)) | Versioned constructor. Caches downloaded asset bundles to a customized cache path. |
| [DownloadHandlerAssetBundle(System.String,System.UInt32)](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/ctor.md#downloadhandlerassetbundle\(string-uint\))                                                  | Standard constructor for non-cached asset bundles.                                 |
| [DownloadHandlerAssetBundle(System.String,System.UInt32,System.UInt32)](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/ctor.md#downloadhandlerassetbundle\(string-uint-uint\))                               | Simple versioned constructor. Caches downloaded asset bundles.                     |
| [DownloadHandlerAssetBundle(System.String,UnityEngine.CachedAssetBundle,System.UInt32)](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/ctor.md#downloadhandlerassetbundle\(string-cachedassetbundle-uint\))  | Versioned constructor. Caches downloaded asset bundles to a customized cache path. |
| [DownloadHandlerAssetBundle(System.String,UnityEngine.Hash128,System.UInt32)](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/ctor.md#downloadhandlerassetbundle\(string-hash128-uint\))                      | Versioned constructor. Caches downloaded asset bundles.                            |

## Properties

| Property                                                                                                                        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [assetBundle](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/assetbundle.md)                 | Returns the downloaded [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md), or `null`. (Read Only)                                                                                                                                                                                                                                                                                                                              |
| [autoLoadAssetBundle](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/autoloadassetbundle.md) | If true, the AssetBundle will be loaded as part of the [UnityWebRequest](/engine/6000.0/script-reference/unityengine/networking/unitywebrequest.md) process. If false, the [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md) will be loaded on demand when accessing the [DownloadHandlerAssetBundle.assetBundle](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/assetbundle.md) property. |
| [isDownloadComplete](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/isdownloadcomplete.md)   | Returns true if the data downloading portion of the operation is complete.                                                                                                                                                                                                                                                                                                                                                                            |

## Methods

| Method                                                                                                  | Description                                                                                                             |
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [GetData](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/getdata.md) | Not implemented. Throws [NotSupportedException](https://msdn.microsoft.com/en-us/library/system.notsupportedexception). |
| [GetText](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/gettext.md) | Not implemented. Throws [NotSupportedException](https://msdn.microsoft.com/en-us/library/system.notsupportedexception). |

## Static Methods

| Method                                                                                                        | Description                                                                                                  |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [GetContent](/engine/6000.0/script-reference/unityengine/networking/downloadhandlerassetbundle/getcontent.md) | Returns the downloaded [AssetBundle](/engine/6000.0/script-reference/unityengine/assetbundle.md), or `null`. |

## Inheritance

**Inherited Members:**

* [DownloadHandler.Dispose()](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/dispose.md)
* [DownloadHandler.isDone](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/isdone.md)
* [DownloadHandler.error](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/error.md)
* [DownloadHandler.nativeData](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/nativedata.md)
* [DownloadHandler.data](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/data.md)
* [DownloadHandler.text](/engine/6000.0/script-reference/unityengine/networking/downloadhandler/text.md)
