# UnityWebRequestAssetBundle

> Helpers for downloading asset bundles using UnityWebRequest.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Networking](/engine/6000.5/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestAssetBundleModule

```csharp
public static class UnityWebRequestAssetBundle
```

## Remarks

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;

// This example demonstrates how to load an AssetBundle asynchronously.
public class AssetBundleLoader : MonoBehaviour
{
    // Load an AssetBundle from a URL asynchronously
    public async Task<AssetBundle> LoadAssetBundleAsync(string url)
    {
        using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url))
        {
            var operation = request.SendWebRequest();

            while (!operation.isDone)
                await Task.Yield();

            if (request.result != UnityWebRequest.Result.Success)
            {
                Debug.LogError($"Failed to load AssetBundle: {request.error}");
                return null;
            }

            return DownloadHandlerAssetBundle.GetContent(request);
        }
    }

    // Example usage
    public async void LoadBundle()
    {
        // Replace this with your own URL.
        // You can use python -m http.server to serve files locally.
        // Remember to first build the AssetBundle
        string bundleUrl = "http://example.com/mybundle.assetbundle";
        AssetBundle bundle = await LoadAssetBundleAsync(bundleUrl);

        if (bundle != null)
        {
            // Load assets from bundle
            GameObject prefab = bundle.LoadAsset<GameObject>("MyPrefab");
            Instantiate(prefab);

            // Remember to unload when done
            bundle.Unload(false);
        }
    }
}
```

Additional Resources: [AssetBundle](/engine/6000.5/script-reference/unityengine/assetbundle.md), [DownloadHandlerAssetBundle](/engine/6000.5/script-reference/unityengine/networking/downloadhandlerassetbundle.md), [UnityWebRequestAssetBundle.GetAssetBundle](/engine/6000.5/script-reference/unityengine/networking/unitywebrequestassetbundle/getassetbundle.md).

## Static Methods

| Method                                                                                                                | Description                                                                            |
| --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [GetAssetBundle](/engine/6000.5/script-reference/unityengine/networking/unitywebrequestassetbundle/getassetbundle.md) | Creates a UnityWebRequest optimized for downloading a Unity Asset Bundle via HTTP GET. |
