Standard Shader becomes totally wrong after building assetbundle

After building assetbundle and load at runtime, My models with standard shader looks totally wrong.

so I checked the item in the inspector, and below is what i saw. Even the shader’s Inspector style was wrong.

I tried assign another shader , and reassign standard shader to the model, then it became right(both inspector and model looking).

Does anyone know how to fix this ? or is this a new reported bug ?

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.

1 Like

Dantus,

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.

Am I missing something?

@sirrus , as already mentioned, it only worked for me in Unity 5.3. Further, I am not using emission, so I don’t know whether this works or not.

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.

If it doesn’t work like that, it is very likely a bug and worth a bug report. Maybe there is already one in the issue tracker, I didn’t check it.

@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?

@pahe , I’m running the Editor on Windows 7 (64-bit) targeting the WebGL platform.

I believe this specific issue occurs in both the editor and in the web build although Ive seen discrepancies between the two with other shaders.

FWIW, I submitted a bug report with a repro case on 12/31 but have not yet heard back.

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.

Sounds like a similar problem we have with OSX editor. Would be great to hear the solution to the problem :slight_smile:

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 :slight_smile:

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

Is this going to be fixed by Unity ???

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.

Please see this thread for details:

… and the documentation on it here:

http://docs.unity3d.com/Manual/AssetBundleFAQ.html

1 Like

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!).

1 Like

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…