- Home /
Why are only some of my scripts missing/"failed to load" only when loading the prefab from a bundle?
When instantiating prefabs loaded from asset bundles, some of their script components give the "referenced script is missing" / "associated script can not be loaded" error and some do not. I can't find any significant difference in the failure cases. So, I'm looking for insight on how this is expected to work.
The bundles contain a single prefab each and are built using (abbreviated):
BuildAssetBundle(AssetDatabase.LoadAssetAtPath("foo.prefab"), CollectDependencies)
The prefabs are loaded using (abbreviated):
WWW www = WWW.LoadFromCacheOrDownload(url, version);
AssetBundle bundle = www.assetBundle;
www.Dispose();
AssetBundleRequest request = bundle.LoadAssetWithSubAssetsAsync("foo.prefab");
yield return request;
GameObject go = request.asset as GameObject;
bundle.Unload(false);
GameObject foo = GameObject.Instantiate(go);
Note that if I comment out "bundle.Unload(false)" everything works fine. But, with the Unload in place, certain scripts fail during instantiation. I am certain that the bundles are not out of sync because I'm rebuilding them during my tests. The scripts are all compiled into my app. I would expect "GameObject go" to hold a reference to the script that survives the Unload. Indeed, that does seem true for some scripts, but not others. I have not identified the difference between the two cases.
Is this expected to work or am I misunderstanding? This is with Unity 5 Beta 22, btw.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182910im_/https://answers.unity.com/themes/thub/images/avi.jpg)