Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

How do you use AssetBundles in a Windows compiled build?

Discussion in 'Asset Bundles' started by ENAYSOFT, Jan 4, 2019.



    Aug 22, 2012

    Unity and also AssetBundle newbie here :)

    Perhaps I don't understand AssetBundles correctly but I'm having trouble using them in Windows after I have compiled a build.

    I've placed the assets in either Assets/AssetBundle directory or Assets/StreamingAssets and they work fine in the Unity Editor.
    But when built nothing happens. I can only assume I haven't included the assetbundles in the build, or something like that.
    Whenever I search about assetbundles it always explains downloading the assets from some website somewhere.
    All I want to do is use AssetBundles offline in the build I've just created. Likely I am missing something very simple since I'm still a newbie.

    If anyone can see what I am doing wrong, it would be greatly appreciated :)

    I'm using the "PC, Mac & Linux Standalone" setting and encoding my assets and loading them using the following code (which I will say again, work ok in the Unity Editor, just not when I make a build)

    Code (CSharp):
    1.     static void BuildAllAssetBundles()
    2.     {
    3.         string assetBundleDirectory = "Assets/AssetBundles";
    4.         if(!Directory.Exists(assetBundleDirectory))
    5.         {
    6.             Directory.CreateDirectory(assetBundleDirectory);
    7.         }
    8.         BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
    9.     }
    Code (CSharp):
    1. var bundleLoadRequest = AssetBundle.LoadFromFileAsync(Application.streamingAssetsPath + "/" + _assetBundleName);
    2.             yield return bundleLoadRequest;
    3.             Debug.Log("bundleLoadRequest finished");
    4.             var myLoadedAssetBundle = bundleLoadRequest.assetBundle;
    5.             if (myLoadedAssetBundle == null)
    6.             {
    7.                 Debug.Log("Failed to load AssetBundle!");
    8.                 yield break;
    9.             }
    11.             var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync<AudioClip>(_fileName);
    12.             yield return assetLoadRequest;
    Many thanks for reading my post. :)
  2. Peter77


    Jun 12, 2013
    I store asset bundles in "Assets/StreamingAssets", because:

    ... and then use AssetBundle.LoadFromFile.

    Here is an example how to load an asset bundle file from StreamingAssets:

    Here is a link to the "A guide to AssetBundles" document:

    If your bundles have dependencies, like BundleB depends on content of BundleA, then you need to load its dependencies first.
    ENAYSOFT likes this.


    Aug 22, 2012
    Hi Peter, many thanks for your detailed post.

    I checked the link for Streaming Assets and noticed

    path = Application.dataPath + "/StreamingAssets";

    which I replaced as mine was

    path =Application.streamingAssetsPath + "/"

    I find it very odd that the official Unity docs regarding StreamingAssets don't even use the

    .streamingAssetsPath tag

    At any rate, through random stabs in the dark, everything is now magically working.

    Again, many thanks. :D
    Peter77 likes this.


    Aug 22, 2012
    Hey Peter77, just wanted to quickly thank you again for your post, I've achieved what I set out to do and learned how StreamingAssets work. :)