Hi there, We are using asset bundles in our WebGL project with Unity 2017.1.0p4 and facing some issues with shaders. Here's our setup : AssetBundle 1 : Contains a module with several textures, materials, prefabs, etc. We have several of such assetbundles AssetBundle 2 : An asset bundle which contains only shaders When loading those bundles the shaders appear pink, any idea why could this comes from ? Is the loading order important ? Thanks a lot .
Add your shader in your "Always Included Shader" in Edit => project settings => Graphics and rebuild your game.
Alright but when you do this, the shader is included in the build, right ? Or is it only a reference, telling that this shader exists.
Yeah that will include it in the build. Do you get any shader compiler errors in the browser console? Also note that shader variants can be tricky with asset bundles in various circumstances. Have you built this project for a different platform (and if so, do the shaders work there)?
Thanks for the answer @kognito1, no I don't get any compilation issue. I guess that assetbundle loading order is important. Because even the material shader name is incorrect. Everything is also well built for the correct plateform.
usually i'd had to do something like this for asset bundles (when getting those missing shaders) Code (CSharp): var renderer = bundleInstance.GetComponent<Renderer>(); if (renderer != null) { var material = Shader.Find(renderer.material.shader.name); renderer.material.shader = null; renderer.material.shader = material; }
Thanks for the answer @mgear. Some time ago I also used this solution but for me it's more of a workaround I would like to avoid doing such thing.
Here are the last discoveries : Materials are in one asset bundle. Shader is not included in the build and in another assetbundle. That causes the pink issue.
It sounds like a shader variant issue. The only time we keep shaders in their own asset bundles is when it's a "non-variant shader". Otherwise we keep the shader untagged and let the "correct variant" get included with the material's bundle.