Search Unity

AssetBundles missing rigidbodies and colliders

Discussion in 'Asset Bundles' started by oakshiro, Apr 26, 2017.

  1. oakshiro

    oakshiro

    Joined:
    Dec 9, 2008
    Posts:
    20
    Hi there,

    It seems my asset bundles have stopped working in Unity5.5

    I have some prefabs on my project, I set a common assetbundle name for them and exported them using this piece of code:

    Code (CSharp):
    1.  BuildPipeline.BuildAssetBundles(bundlePath, BuildAssetBundleOptions.None, BuildTarget.Android);
    (BTW, it's an android only game)

    When I instantiate the asset, it has no rigidbody nor collider attached, its just a plain gameObject. Any clue?

    This is the code I use to instantiate them...

    Code (CSharp):
    1.   using (WWW www = WWW.LoadFromCacheOrDownload(url, version))
    2.             {
    3.  
    4.                 float timer = 0;
    5.                 bool failed = false;
    6.  
    7.                 while (!www.isDone)
    8.                 {
    9.                     if (timer > timeOut) { failed = true; break; }
    10.                     timer += Time.deltaTime;
    11.                     yield return null;
    12.                 }
    13.  
    14.                 if (failed)
    15.                 {
    16.                     //TODO: show error popup
    17.                     Debug.LogError("WWW download timeout!");
    18.                     SceneManager.LoadScene("MainMenu");
    19.                     Destroy(this.gameObject);
    20.                 }
    21.  
    22.                 if (www.error != null)
    23.                 {
    24.                    //TODO: show error popup
    25.                     Debug.LogError("WWW download had an error:" + www.error);
    26.                     Destroy(this.gameObject);
    27.                 }
    28.  
    29.                 // Load and retrieve the AssetBundle
    30.                 AssetBundle bundle = www.assetBundle;
    31.  
    32.                 // Load the object asynchronously
    33.                 AssetBundleRequest request = bundle.LoadAssetAsync(asset, typeof(GameObject));              
    34.  
    35.                 // Wait for completion
    36.                 yield return request;
    37.  
    38.                 // Get the reference to the loaded object
    39.                 GameObject InstanceObj = request.asset as GameObject;
    40.  
    41.                 //instantiate this asset
    42.                 GameObject newInstance = (GameObject)Instantiate(InstanceObj) as GameObject;
    43.  
    44.                 }
    45.  
    46.                 bundle.Unload(false);
    47.             } // memory is freed from the web stream (www.Dispose() gets called implicitly)

    Thank you very much!
     
  2. oakshiro

    oakshiro

    Joined:
    Dec 9, 2008
    Posts:
    20
    Ok, Answering myself, just in case anyone has the same problem. It was all because I had both the prefabs and the meshes included in the assetbundles group, and both prefab and mesh had the same name.
    Whenever I instantiated an asset by name, the mesh was being instantiated instead of the prefab.

    Removing the meshes from the assetbundle group fixed the issue.

    Thanks to all
     
    Quadangles and Cipic like this.