Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't load AssetBundle in .exe build, works in Editor?

Discussion in 'Editor & General Support' started by paulrahme, Jun 7, 2012.

  1. paulrahme

    paulrahme

    Joined:
    Apr 25, 2012
    Posts:
    17
    Hi,

    There's a similar thread in the Scripting forum:
    http://forum.unity3d.com/threads/136141-Asset-bundles-loading-inside-editor-and-WebPlayer-but-not-in-exe-and-mobile?highlight=assetbundle
    ...but haven't managed to get an answer there. Since my problem is with AssetBundles not loading in a build (rather than the scripting to create them), it makes sense to ask here.

    Our AssetBundles are built using the following command:
    Code (csharp):
    1. BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows, BuildOptions.UncompressedAssetBundle);
    2.  
    I originally tried Compressed bundle but it refuses to open - says it got type UnityWeb, expected UnityRaw. Compressed would be preferable, but not too important since the AssetBundles are included with our app, just different combinations for different clients.

    It loads fine in the Unity Editor (Unity 3.5.2f2, tested on both Windows XP Windows 7), but on a build version (.exe) it does not load.

    Looking at the generated ..._Data/output_log.txt, the error given is:
    The asset bundle 'AssetBundles/Common Icons.unity3d' can't be loaded because it was not built with the right version or build target.

    (Filename: C:/BuildAgent/work/300357e52574df36/Runtime/Misc/AssetBundleUtility.cpp Line: 542)


    Highly frustrating, since we can currently see it working in Editor mode, but can't take it demo it to clients off a build version :(

    Anyone have any advice/suggestions? Thanks in advance...
     
  2. paulrahme

    paulrahme

    Joined:
    Apr 25, 2012
    Posts:
    17
    SOLVED

    Found the problem! In case anyone else is interested - may help with similar AssetBundle.CreateFromFile() issues:

    The "not built with the right version or build target" error was coming up in build mode, because it could not open the file. Unity's AssetBundle.CreateFromFile() function seems to assume the file opened ok, tries to read garbage, and panics about not knowing what to do with it.

    I was using a relative path to where the .exe is running, eg.
    Code (csharp):
    1. CreateFromFile("AssetBundles/Common Icons.unity3d");   // this does not work
    which works fine on Directory. and File. operations, but not AssetBundle.CreateFromFile().

    Using an absolute file path works ok, eg.
    Code (csharp):
    1. CreateFromFile("C:\\temp\\mybundle.unity3d")
    so use Application.dataPath (possibly in conjunction with Directory.GetParent) to get the absolute path to your asset bundle.
     
    Last edited: Jun 11, 2012