The Standard Shader gets stripped when building the assetbundles, so it isn’t the same anymore when you load it from the assetbundle and assign it to your shader, as it would be if you assign it in the editor.
If you have problems with lighting, you should check if your lightmap mode is stripped from the shader when building the assetbundles.
Additionally, note that you have build the assetbundles for the correct platform. iOS assetbundles won’t work on Android or PC and vice versa.
Not to dig up this thread but we’ve experienced this since Day 1 of the Standard Shader and have had to make serious modifications to our project to avoid using the Standard Shader. Is this “stripping of standard shader” documented somewhere?
If true, how are we supposed to display materials using the Standard Shader when loaded from an assetbundle??
You can specify in the graphics settings that the standard shader or some variants should not be stripped. Like that they become part of the actual build and the asset bundles are loaded correctly. If I remember correctly there were issues with certain Unity 5.x versions, but it is working in Unity 5.3.
Thanks for the response but the standard shader is already included in the list of “Always Included”. My understanding is that using precompiled shader variants OR including shader variants in the scene should register the standard shader properties correctly. Still doesnt seem to be working for us, either using shader variants OR the exact material in the project.
Example:
Created an asset with material that has Standard Shader, Emission Map (and Albedo texture). Looks great. Built assetbundle of this asset.
Placed exact material (with standard shader properties and textures) into a GameObject in the scene.
Downloaded assetbundle at runtime (in Editor) and there is absolutely no emission on the asset yet the properties are all set correctly in the inspector on that material.
If I then manually select “Standard” from the shader list for that material, it emits perfectly.
I’m in 5.3.0f1. I’ve had the same issue with various shader properties, including the render mode and normal maps. Was hoping this thread would shed some light (eww… sorry for the pun) on the issue.
@sirrus May I ask on which platform you are using the editor? We’ve got severe problems on Mac OS where some shaders are not working at all when downloaded from assetbundles, but work fine on Windows and on all other runtime platforms. So is this problem only occuring in the editor or also on your target platform later?
After some further testing, it looks as though this may just be an issue in the editor (possibly only for WebGL target). Various shader properties (emission, render mode) now seem to render correctly in a published build but look wrong in the editor.
Haven’t heard from Unity on the bug report. It makes testing assets a bit frustrating since we can’t visually confirm their quality in the editor. Id love to hear a solution too
I have the same issue : materials become totally wrong when loaded from an AssetBundle :
sometimes it is pink,
sometimes it behaves not correctly (everything looks normal in the inspector but no transparency, or no shadows, or no pixel lighting…)
sometimes it just crashes.
And manually “fixing” the material by selecting again the shader in the inspector while the game is running makes the material work.
Of course, there is the mat.shader = Shader.Find(mat.shader.name) trick that works, well, sometimes, and crashes, sometimes…
See my post about that : AssetBundles and dependencies - Unity Engine - Unity Discussions
No, they are not going to fix it. Depending on the target platform you are using, assetbundles will not load the same in the Editor as they will in a published build.
I could understand the problem, that assetbundles from other platforms would not work in the editor. My Android or XBox shaders may differ from the used ones in the editor, which I assume is using the Standalone version. But how are we able to use the same Standalone assetbundle for OSX and Windows?
Am I right that we are supposed to build one Assetbundle for OSX editor and one for Windows then?
Okay, after some work, I changed our assetbundle process to create seperate standalone assetbundles for windows and OSX. This solved the problem that the shaders are shown in pink on OSX, but they are only shown in the scene view, the game view seems to be broken. I haven’t investigated this yet, but just maybe anyone else could confirm that this would solve the assetbundle problem for his editor?
After some other fixes to our asset pipeline, I can say that the change actually fixed our problem with the broken shaders. So if you experience problems with shaders in assetbundles, make sure you are building for the right platform (even standalone needs own shaders for windows/osx now!).
I am facing the same Issue. I am building for android and also while building assetBundles I have set the platform to android Still the problem is not solved…