UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[Shaders] Eliminate Slow Builds: Fix Shader Stripping in URP

Solution

memory managementbuild optimizationperformanceuniversal render pipelineproject settings

Unity 2021.3.x - Unity 6.3.x

Published Sun, Mar 8

Issue

 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.

Explanation

Shader variant management is critical for performance and build efficiency in Unity 6. Follow these steps to resolve stripping issues and long build times:

  1. Open Edit > Project Settings > Player.
  2. Locate the Other Settings section.
  3. Disable Strict Variant Matching. This prevents the engine from aggressively removing variants not explicitly referenced, ensuring keywords like DOTS_INSTANCING_ON remain available at runtime.
  4. Navigate to Edit > Project Settings > Graphics.
  5. Under the Shader Stripping section, 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.
  6. Align these settings with your project’s target rendering features to ensure stability.
  7. For more fine-grained control over included variants, use a ShaderVariantCollection asset and explicitly add required variants; however, disable Strict Variant Matching first for immediate relief.

Additional Tips

  • Monitor the Shader Compilation log in the Console to identify which specific variants are causing delays.
  • For projects migrated from older versions, perform a clean build by deleting the Library folder to reset the shader cache.
  • Utilize IPreprocessShaders scripts to programmatically strip variants that are known to be unused by your target hardware.
  • Verify that your ShaderVariantCollection is correctly assigned to the Preloaded Shaders list in Graphics settings.

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.