Hello everyone,
I’ve been stuck on this issue for the past few days.
I build out the AssetBundle with the following tool:
Here are the build settings.
I then upload the AssetBundle to an AWS bucket.
I use the following code to build the asset bundles:
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
string assetBundleDirectory = "Assets/StreamingAssets";
if (!Directory.Exists(Application.streamingAssetsPath))
{
Directory.CreateDirectory(assetBundleDirectory);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
}
}
I then use the following code to pull the asset bundles:
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class BundleWebLoader : MonoBehaviour
{
public string bundleUrl = "https://aws-bucket-url/AssetBundles/WebGL/resources";
// Start is called before the first frame update
IEnumerator Start()
{
//DontDestroyOnLoad(this.gameObject);
UnityWebRequest web = UnityWebRequestAssetBundle.GetAssetBundle(bundleUrl, 0, 0);
yield return web.SendWebRequest();
if (web.isNetworkError || web.isHttpError)
{
Debug.Log(web.error);
} else {
AssetBundle remoteAssetBundle = DownloadHandlerAssetBundle.GetContent(web);// web.assetBundle;
if (remoteAssetBundle == null)
{
Debug.LogError("Failed to download AssetBundle!");
yield break;
}
string[] rootAssetPaths = remoteAssetBundle.GetAllAssetNames();
MonsterDataManager.resourcesAssets = remoteAssetBundle;
SceneManager.LoadScene("MainMenu");
}
}
}
As you can see in the image and with the code, this is being built out to WebGL.
I thought the issue might be related to the bundle size as I’ve read the max size is 4GB. I ran the bundle uncompressed which output a 3.4GB file (107MB when compressed).
The following code and setup works successfully within the Unity editor. This fails when deployed an Angular app.
I suspect it may come down to this line of code: (URI, version, crc)
UnityWebRequest web = UnityWebRequestAssetBundle.GetAssetBundle(bundleUrl, 0, 0);
When I remove the 2nd and 3rd param this no longer properly works in the Unity editor, however, I no longer get the Asset Bundle version error (though the assets still do not load).
Any help would be greatly appreciated! Using Unity 2021.3.0f1.