AssetBundles missing rigidbodies and colliders

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:

 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…

  using (WWW www = WWW.LoadFromCacheOrDownload(url, version))
            {

                float timer = 0;
                bool failed = false;

                while (!www.isDone)
                {
                    if (timer > timeOut) { failed = true; break; }
                    timer += Time.deltaTime;
                    yield return null;
                }

                if (failed)
                { 
                    //TODO: show error popup
                    Debug.LogError("WWW download timeout!");
                    SceneManager.LoadScene("MainMenu");
                    Destroy(this.gameObject);
                }

                if (www.error != null)
                {
                   //TODO: show error popup
                    Debug.LogError("WWW download had an error:" + www.error);
                    Destroy(this.gameObject);
                }

                // Load and retrieve the AssetBundle
                AssetBundle bundle = www.assetBundle;

                // Load the object asynchronously
                AssetBundleRequest request = bundle.LoadAssetAsync(asset, typeof(GameObject));               

                // Wait for completion
                yield return request;

                // Get the reference to the loaded object
                GameObject InstanceObj = request.asset as GameObject;

                //instantiate this asset
                GameObject newInstance = (GameObject)Instantiate(InstanceObj) as GameObject;

                }

                bundle.Unload(false);
            } // memory is freed from the web stream (www.Dispose() gets called implicitly)

Thank you very much!

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

3 Likes