[Shaders] Eliminate Slow Builds: Fix Shader Stripping in URP
Solution
Unity 2021.3.x - Unity 6.3.x
Published Sun, Mar 8
Projects utilizing Universal Render Pipeline (URP) experience missing shader variants and excessive build times. Strict Variant Matching often causes critical keywords like DOTS_INSTANCING_ON to be stripped, leading to application crashes and severe performance drops. Build durations can extend to several days due to unoptimized shader permutations.
Prevent DOTS_INSTANCING_ON stripping and reduce build durations by disabling Strict Variant Matching and optimizing Graphics settings.
Shader variant management is critical for performance and build efficiency in Unity 6. Follow these steps to resolve stripping issues and long build times:
- Open
Edit > Project Settings > Player. - Locate the
Other Settingssection. - Disable Strict Variant Matching. This prevents the engine from aggressively removing variants not explicitly referenced, ensuring keywords like
DOTS_INSTANCING_ONremain available at runtime. - Navigate to
Edit > Project Settings > Graphics. - Under the
Shader Strippingsection, ensure only required rendering features are enabled. Toggling off unused features (e.g.,Point Lights,Shadow Masks) directly reduces the number of generated permutations, significantly shortening build duration. - Align these settings with your project’s target rendering features to ensure stability.
- For more fine-grained control over included variants, use a
ShaderVariantCollectionasset and explicitly add required variants; however, disable Strict Variant Matching first for immediate relief.
Additional Tips
- Monitor the
Shader Compilationlog in theConsoleto identify which specific variants are causing delays. - For projects migrated from older versions, perform a clean build by deleting the
Libraryfolder to reset the shader cache. - Utilize
IPreprocessShadersscripts to programmatically strip variants that are known to be unused by your target hardware. - Verify that your
ShaderVariantCollectionis correctly assigned to thePreloaded Shaderslist inGraphicssettings.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.