Unity 5 - AssetBundles and Shaders

Hey everyone,

I have several questions concerning asset bundles and shaders.

First simple question, I’ve discovered the new asset bundle system which is really cool but I am wondering if there’s a way to build only one asset bundle maybe bases on its name.

Next question is linked with shaders. I have two custom shaders and two asset bundles which contains a simple sphere, a material with a one of the shaders each.
Both asset bundles are build for WebGL and both shaders are correctly loaded in the browser. But in the editor one of the asset bundle is purple because it can’t load the shader. But with a simple Shader.Find on the asset bundle material and it works but it seems a bit strange.

Any idea why some asset bundle shaders are not loaded correctly inside the editor ?

Thanks a lot !

Here is a small update. I noticed that when loading the shader inside WebGL, it works but not completely, there are some lighting issues and when doing a Shader.Find, it works.

But again, I don’t understand why I should do a Shader.Find.

This has been discussed here and here. Issue Tracker here.

I also noticed two other strange behaviours.

When using the Shader.Find trick and reassigning the shader to the material which is transparent, I need to set all the properties like in the StandardShaderGUI.cs to make it work or it is simply not transparent at all.

material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;

Another strange issue concerns Asset Bundle loading and Resources loading. When Instantiating a GameObject using those systems some properties of shaders does not behave the same compared to a classic instantiation from a prefab.

// This does not behave the same when loading from Asset Bundle/Resources or from a classic Prefab
mul(_World2Object, float4(0.0, 0.0, 0.0, 1.0));