Search Unity

Ridiculous building times for URP assets?

Discussion in 'Universal Render Pipeline' started by ClosingTime, Apr 28, 2022.

  1. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    I have downloaded the free package from Unity, of https://assetstore.unity.com/packages/3d/environments/unity-terrain-urp-demo-scene-213197

    It works nice in my game in the editor, but once I am trying to build this for a Windows Exe, it takes an obscene amount of time to build.

    I even use a small portion of it. It renders some aspects of Unity not usable, because in practice it is way too hard to work with it due to build times.

    Why Unity builds everything, even things I don't use? And why URP shaders and assets take so long to build for Windows?

    I have a Ryzen 7 2700X, not a super slow CPU

    Is there a way to prevent Unity from those hours long builds?
     
  2. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    If you go to the global urp settings, there's a few options for shader stripping. Make sure they're all enabled to strip as much as possible.

    The first build will always take the longest, but subsequent builds should be much faster unless you're changing shader data.
     
  3. RichardGoesToNightSchool

    RichardGoesToNightSchool

    Joined:
    Dec 9, 2020
    Posts:
    27
    Out of curiousity, what quailfies as changing the shader data?
     
  4. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Adding or editing .shader or .shadergraph files
    In a way you could also count changing some toggles on shaderguis which change shader keywords (triggering a recompile of the shader) but that is not really the same.

    I remember that in 2021.2.xyz there was a bug which created a looooot more shadervariants than needed.
     
  5. RichardGoesToNightSchool

    RichardGoesToNightSchool

    Joined:
    Dec 9, 2020
    Posts:
    27
    Ahh, that makes sense, thanks.

    Do you know if toggling a feature that wasn't being used before triggers a full recompile or just the variants needed?
     
  6. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Do you know if toggling a feature that wasn't being used before triggers a full recompile or just the variants needed?[/QUOTE]
    I guess only the variants needed, but I am not 100% sure
     
  7. dnach

    dnach

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    89
    In such case (toggling certain RP features or editing the shader source), re-building the project should only compile the necessary shaders / variants. The Editor also compiles and caches shader variants that are needed for viewport rendering.

    You can use the Editor log to track the variants actually being compiled during build:
    Code (Text):
    1. Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (fp)
    2.   [2.09s] 100M / ~100M prepared
    3.     320 / 786432 variants left after stripping, processed in 6.77 seconds
    4.     starting compilation...
    5.     finished in 29.72 seconds. Local cache hits 202 (0.24s CPU time), remote cache hits 0 (0.00s CPU time), compiled 118 variants (582.41s CPU time), skipped 0 variants
    Above log is for 2020.2+ , but prior to this version you can also enable Shader Variant Log level in the URP/HDRP asset settings.

    We understand the long build times are a huge pain, and are working on an immediate optimization for reducing shader build times via variant keyword prefiltering. Please check out the official announcement for more detail on upcoming improvements, as well as useful information on shader variant logging and stripping: https://forum.unity.com/threads/improvements-to-shaders-build-time-and-runtime-memory-usage.1305615/
     
    LeonhardP and ClosingTime like this.
  8. RichardGoesToNightSchool

    RichardGoesToNightSchool

    Joined:
    Dec 9, 2020
    Posts:
    27
    Thanks! This logging tip is super helpful!!