Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Standard Shader duplicated in Asset Bundle Build

Discussion in 'Asset Bundles' started by FallenTreeGames, Dec 5, 2018.

  1. FallenTreeGames

    FallenTreeGames

    Joined:
    Jun 22, 2016
    Posts:
    22
    Hey,

    I've been investigating why our asset bundle builds use more memory than our non-bundle builds, and have narrowed it down to the shaders.

    The detailed memory view shows us that on an asset bundle build, ShaderLab takes up around 350mb, whilst on a non-asset bundle build it uses < 80mb.

    So I dumped out the list of all loaded shaders with Resources.FindObjectsOfTypeAll<Shader>() and the result is that the asset bundle build has numerous copies of some shaders, including 27 copies of the Standard shader, and 31 copies of the Standard (Specular setup) one. (The non-asset bundle build has only one copy of each).

    How do I fix this? Some of the shaders that are duplicated are custom shaders which are not being included in the correct asset bundle (so fair enough) but how do I fix this for the standard shader?
     
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    162
    For built-in shaders, our current recommendation if you are using the BuildPipeline.BuildAssetBundles API is to download the built-in shaders from https://unity3d.com/get-unity/download/archive (click the drop down array next to "Downloads (Win)" or "Downloads (Mac)" to get the "Built in shaders") and copy the ones you want to de-duplicate into your project, renaming the shader internal name to something like "YourProject/Standard". From there you can then assign it to a specific bundle and it will no longer be duplicated. You will need to update all your assets to point to this shader copy instead of the original shader, this can be done with an AssetPostprocessor (https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html) and reimport of your assets.

    In the Scriptable Build Pipeline, we have provided some simple code that will de-duplicate built-in shaders automatically as an example.
     
  3. FallenTreeGames

    FallenTreeGames

    Joined:
    Jun 22, 2016
    Posts:
    22
    Hey,

    Thanks for that. It was the solution I was thinking of, though I assumed it was more of a hack.

    Is the Scriptable Build Pipeline ready for production use?
     
  4. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    162
    Disclaimer: It's still in Preview, so we do not recommend it for production use.

    That being said, if you are not using Asset Bundle Variants and using full Asset Paths to load, you can try out SBP with only a single line code change and switch back if you are having issues. So far, most issues we've run into have been really simple fixes for us to track down and push out a change to fix.
     
  5. FallenTreeGames

    FallenTreeGames

    Joined:
    Jun 22, 2016
    Posts:
    22
    Okay thanks! I'll get sorting this at some point and see if I have any issues :)