

Your game looks perfect in the Editor. Materials render correctly. Effects work as expected. Then you make a build — and suddenly some objects turn pink, render without effects, or lose important visual features.
This is often caused by missing shader variants in the final build.
Unity strips unused shader variants during the build process to reduce size and improve performance. Unfortunately, this sometimes removes variants that are actually needed at runtime.
Modern Unity shaders generate multiple internal versions called variants. Each variant represents a different combination of keywords and features.
For example, a shader might have variants for:
Unity only includes variants it believes are required. If a variant is triggered dynamically at runtime, it may not be included in the build.
Unity strips shader variants when:
If Unity does not detect the variant during build analysis, it removes it.
Unity allows you to explicitly record and include shader variants.
Steps:
At runtime, you can warm up the collection:
using UnityEngine;
public class ShaderWarmup : MonoBehaviour
{
public ShaderVariantCollection collection;
void Awake()
{
if (collection != null)
{
collection.WarmUp();
}
}
}
This ensures required variants are compiled and included.
Go to:
Edit → Project Settings → Graphics
Under Always Included Shaders, add the shaders that disappear in builds.
This forces Unity to include all variants of that shader.
Be cautious. This can increase build size significantly.
Enabling shader keywords dynamically can cause stripping problems.
Example:
material.EnableKeyword("_NORMALMAP");
If this keyword is never enabled during build analysis, its variant may not be included.
Solution:
In URP:
In HDRP:
Pipeline settings directly affect variant inclusion.
If shaders are used only inside Addressables or dynamically loaded prefabs, Unity may not detect them during build.
Solution:
If the problem disappears, it was a stripped variant.
Including too many variants increases:
Do not disable stripping entirely in production. Instead, include only necessary variants.
Not exactly. Shader stripping is an optimization system designed to reduce unused shader combinations. The issue appears when runtime behavior does not match what Unity detects during build analysis.
If materials turn pink or effects disappear only in builds, suspect shader variant stripping first.
Use Shader Variant Collections carefully, manage keywords intentionally, and verify pipeline stripping settings. Once controlled properly, shader variant issues become predictable and preventable.