I’m trying to stuff our project’s prefabs into AssetBundles. But after building the asset bundle, loading it into the scene reveals that the prefab no longer has the appropriate material attached, though it should have made it into the AssetBundle. Using code to manually pull out the Material also doesn’t work.
Can anybody help? A small example project is attached. I’m creating the bundle with:
Object[] assets = new Object[]
{
AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Cube.prefab", typeof(GameObject)),
AssetDatabase.LoadAssetAtPath("Assets/Prefabs/CubeMaterial.mat", typeof(Material)),
(AssetDatabase.LoadAssetAtPath("Assets/Prefabs/CubeMaterial.mat", typeof(Material)) as Material).mainTexture,
AssetDatabase.LoadAssetAtPath("Assets/Scripts/Rotate.cs", typeof(Object))
};
BuildPipeline.BuildAssetBundle(Selection.activeObject, assets, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, EditorUserBuildSettings.activeBuildTarget);
The object is being loaded with:
using (WWW www = WWW.LoadFromCacheOrDownload(bundlePath, 0))
{
yield return www;
AssetBundle ab = www.assetBundle;
www.Dispose();
GameObject cube = Instantiate(ab.Load("Cube")) as GameObject;
// This shouldn't even be necessary:
cube.renderer.material = ab.Load("CubeMaterial", typeof(Material)) as Material;
ab.Unload(false);
}
Thanks!
1123097–42389–$AssetBundleTest.zip (1.42 MB)