Quick answer: Switch multi_compile directives to shader_feature where the option is selected by Material rather than runtime SetKeyword. Implement an IPreprocessShaders to strip URP variants you don’t use. Build Report → Shader Variants finds the worst contributors.

Build halts: “ShaderLab: Maximum number of keywords exceeded.” You added one more shader feature and the per-build cap finally tipped over. Most of the keywords are URP variants you don’t need.

The Symptom

Build fails with global keyword count exceeded. May reference a specific shader or just bail mid-compilation. Smaller projects may not hit this; larger or URP-heavy projects often do.

The Fix

Step 1: shader_feature for material-driven options.

// Bad — always built
#pragma multi_compile _ _USE_DETAIL_TEX

// Good — only built if a Material in the project enables it
#pragma shader_feature _ _USE_DETAIL_TEX

shader_feature strips at build time based on actual material usage. multi_compile keeps every combination always.

Step 2: Strip URP/HDRP variants you don’t use. Project Settings → Graphics → URP Asset → Lighting:

Strip Unused Variants:        true
Strip Screen Coordinates:     true     // if you don't use them
Strip _MainLight Shadows:     false    // keep, you probably do
Strip Additional Lights:      true     // if no point/spot

Dropping unused light/shadow variants alone can save thousands of keywords.

Step 3: Implement IPreprocessShaders. For surgical control, strip combinations you know are unused:

public class StripFog : IPreprocessShaders
{
    ShaderKeyword fogKeyword = new("FOG_LINEAR");
    public int callbackOrder => 0;
    public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
    {
        for (int i = data.Count - 1; i >= 0; i--)
            if (data[i].shaderKeywordSet.IsEnabled(fogKeyword)) data.RemoveAt(i);
    }
}

Find the Worst Offenders

Build Report (Window → Analysis → Build Report) shows shader variant counts. Custom shaders with 32+ variants are usually fixable by switching multi_compile to shader_feature.

Verifying

Build again. Should succeed. Build Report shows new (lower) variant total. If still over the limit, identify the largest contributors and strip more.

“shader_feature where possible. Strip URP variants. IPreprocessShaders for surgical cuts. Builds.”

Related Issues

For shader build stripping, see build shader updates. For SRP Batcher, see SRP Batcher.

shader_feature. Strip URP. Build succeeds.