AssetBundles don't contain materials (example attached).

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)

Yes, I have found the same. It seems that the built runtime works correctly but in editor there are something wrong with the AssetBundles.
We use similar hack to load the materials/shaders explicitly after the AssetBundle is loadad…

So, please submit a bug report!

As a general note, it is really sad that the AssetBundles are (also) “left on their own” ie. no lightmap support (without own hacks) etc.,
I thought we paid for these Pro features so that we wouldn’t need to do all our-self !?

Can you store materials in the asset bundle at all? Because after building the bundle I can’t load the material at all. (I suppose I could create it dynamically but this is getting to be a lot of work.)