0
\$\begingroup\$

I am trying to load a bunch of prefabs from an asset bundle. I am building the asset bundles for StandaloneWindows64:

BuildPipeline.BuildAssetBundles(BuildPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);

I load my asset bundle using Unity's new web request system:

var www = UnityWebRequest.GetAssetBundle(Url);
yield return www.Send();
if (www.isError)
{
    Debug.LogError(www.error);
    yield break;
}
var bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;

However, my bundle does not have my asset bundle in it. It only has the manifest:

//Output:  "1 asset: bundlemanifest"
Debug.Log(bundle.GetAllAssetNames().Length + " asset: " + bundle.GetAllAssetNames()[0]);

If I look at my manifest, I can see my asset bundle names "structures" does exist:

ManifestFileVersion: 0
CRC: 3317959940
AssetBundleManifest:
  AssetBundleInfos:
    Info_0:
      Name: structures
      Dependencies: {}

I tried retrieving it from my AssetBundleManifest:

var manifest = bundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");

But the AssetBundleManifest only has functions which return strings and Hash128s.

How can I instantiate the prefabs in my asset bundle named "structures"?

\$\endgroup\$
12
  • \$\begingroup\$ Can you clarify what you're doing with the results of BuildPipeline.BuildAssetBundles and where Url points (in your web request). BuildPipeline.BuildAssetBundles returns a manifest and then BuildPath is where the bundles are created. Note that each bundle also has a corresponding .manifest file that can be ignored in most cases; the actual bundle wont have an extension and that's the file you want to load. \$\endgroup\$
    – Foggzie
    Feb 22, 2017 at 20:26
  • \$\begingroup\$ I also noticed you tagged the question with "streaming-assets". If you're putting the bundles in Application.streamingAssetsPath, you don't need to deal with WWW, you can directly call AssetBundle.LoadFromFile. (WWW creates excessive amounts of garbage so only use it if you must) \$\endgroup\$
    – Foggzie
    Feb 22, 2017 at 20:29
  • \$\begingroup\$ @GuntherFox I am taking the asset bundles/manifests/etc and putting them on a local server. I am then using the URL of that local server. \$\endgroup\$
    – Evorlor
    Feb 22, 2017 at 20:40
  • \$\begingroup\$ Does your URL include the underscore and the hash for the actual bundle file? When you build a bundle named "structures" it will create two files: one named structures.manifest and one named structures_XXXXXXXX where the X's are a hash. You want to make sure you're downloading the one with the underscore, hash, and no file extension. \$\endgroup\$
    – Foggzie
    Feb 22, 2017 at 21:09
  • \$\begingroup\$ @GuntherFox OK. I have no idea. This is where I am stuck? I cannot find access to my structures. The only reference I can find to it is the string name of it, which is not helpful. \$\endgroup\$
    – Evorlor
    Feb 22, 2017 at 21:18

1 Answer 1

0
\$\begingroup\$

My URL required the name of the asset bundle at the end of it. I had the parent folder as my asset bundle's name, which loaded the Asset Bundle Manifest for some reason.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .