Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Standard Shader becomes totally wrong after building assetbundle

Discussion in 'Shaders' started by ShuraK, Aug 7, 2015.

  1. ShuraK

    ShuraK

    Joined:
    Jan 15, 2015
    Posts:
    23
    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 ?


     

    Attached Files:

  2. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    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.
     
  3. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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??
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    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.
    http://docs.unity3d.com/Manual/class-GraphicsSettings.html
     
    pahe likes this.
  5. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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:
    1. Created an asset with material that has Standard Shader, Emission Map (and Albedo texture). Looks great. Built assetbundle of this asset.
    2. Placed exact material (with standard shader properties and textures) into a GameObject in the scene.
    3. 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.
    4. If I then manually select "Standard" from the shader list for that material, it emits perfectly.
    Am I missing something?
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @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.
     
  7. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    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.
     
  9. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @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?
     
  10. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    @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.
     
  11. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    FWIW, I submitted a bug report with a repro case on 12/31 but have not yet heard back.
     
  12. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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.
     
  13. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Sounds like a similar problem we have with OSX editor. Would be great to hear the solution to the problem :)
     
  14. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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 :)
     
  15. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    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 : http://forum.unity3d.com/threads/assetbundles-and-dependencies.377760/

    Is this going to be fixed by Unity ???
     
  16. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    hopeful likes this.
  17. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    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?
     
  18. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    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?
     
  19. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    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!).
     
    Dantus likes this.
  20. shekhar331

    shekhar331

    Joined:
    Nov 11, 2014
    Posts:
    10
    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....
     
  21. jana553

    jana553

    Joined:
    May 31, 2018
    Posts:
    7
    I have also faced same issue, after including standard shader to always included shaders, it worked fine in editor but later, in Standalone-windows build is crashing randomly, am I missing anything? please help me.

    Thanks in advance.
     
    Last edited: May 18, 2020
    tomekkie2 likes this.
  22. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    Still the same issue, I am lucky to find this thread.
    Does anyone know if this is still a problem when using Addressables?
     
  23. Deleted User

    Deleted User

    Guest

    @tomekkie2 yes, I have same problem right now :(
     
  24. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Same issue here!
    This include the Autodesk Interactive shader too ;)
     
  25. Kekaku

    Kekaku

    Joined:
    Oct 24, 2018
    Posts:
    7
    How could this problem still not be solved??!! Sucks!
     
    Klausbdl likes this.