Version: Unity 6.1 Alpha (6000.1)
Language : English
Strip shader variants
Control how much memory shaders use

Troubleshooting shader duplication from AssetBundles

If you use AssetBundles, Unity might compile duplicate shaders if you reference one shaderA program that runs on the GPU. More info
See in Glossary
in two or more objects. For example:

  • A material in an AssetBundle and a material in a built sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
    See in Glossary
    reference the same shader.
  • Multiple AssetBundles contain materials that reference the same shader outside an AssetBundle.

This can increase the memory and storage space shaders use, and break draw call batching.

To avoid this, you can use the following approaches:

  • Load an AssetBundle that contains all your shaders first, then load and instantiate AssetBundle assets that reference the shaders. See AssetBundle Dependencies for more information.
  • Structure your AssetBundles to minimise duplication. See Asset Duplication for more information.

You can add materials and shader variant collections to an AssetBundle to specify which shader variants to include.

If you create a single AssetBundle, some shaders might stay in memory even if they’re no longer needed, because you cannot partially unload an AssetBundle. You can avoid this by creating a separate AssetBundle for each group of shaders you use together, for example a ‘forest’ AssetBundle and a ‘desert’ AssetBundle. See Managing loaded AssetBundles, or Memory management in the Addressables system if you use Addressables.

Strip shader variants
Control how much memory shaders use