
Unity Shadow Acne Bug: Artifacts in Shadow Maps and Reliable Fixes
February 20, 2026
Unity Audio Clip Bug: Sounds Cutting Off Prematurely
February 20, 2026Your 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.
What Are Shader Variants?
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:
- Shadows enabled or disabled
- Lightmaps on or off
- Normal maps enabled
- Fog enabled
- Different rendering paths
Unity only includes variants it believes are required. If a variant is triggered dynamically at runtime, it may not be included in the build.
Common Symptoms
- Pink materials in build only
- Particles missing effects
- URP features not rendering
- Post-processing missing in build
- Works in Editor but broken in build
Why Variants Go Missing
Unity strips shader variants when:
- A keyword is enabled via script at runtime
- A material is loaded dynamically (Addressables or Resources)
- Graphics settings do not include the shader
- Shader features are conditionally compiled
If Unity does not detect the variant during build analysis, it removes it.
Fix 1: Create a Shader Variant Collection
Unity allows you to explicitly record and include shader variants.
Steps:
- Open Graphics Settings
- Create a Shader Variant Collection asset
- Assign it in the “Preloaded Shaders” section
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.
Fix 2: Add Shaders to Always Included Shaders
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.
Fix 3: Avoid Runtime Keyword Surprises
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:
- Use a material in the scene with that keyword enabled
- Include it via Shader Variant Collection
Fix 4: URP and HDRP Specific Settings
In URP:
- Check the URP Asset → Shader Stripping settings
- Disable aggressive stripping during debugging
In HDRP:
- Verify HDRP Global Settings
- Ensure required features are enabled in the pipeline asset
Pipeline settings directly affect variant inclusion.
Fix 5: Addressables and Resources
If shaders are used only inside Addressables or dynamically loaded prefabs, Unity may not detect them during build.
Solution:
- Include a reference material in a test scene
- Or use a Shader Variant Collection
How to Confirm It Is a Variant Issue
- Switch build target and compare behavior
- Disable shader stripping temporarily
- Add shader to Always Included and test again
If the problem disappears, it was a stripped variant.
Performance Considerations
Including too many variants increases:
- Build size
- Build time
- Memory usage
Do not disable stripping entirely in production. Instead, include only necessary variants.
Is This a Unity Bug?
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.
Final Thoughts
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.










