Search Unity

Unity freezes when compiling shader variants

Discussion in 'Editor & General Support' started by dasprid, Jul 9, 2020.

  1. dasprid

    dasprid

    Joined:
    Jun 22, 2020
    Posts:
    4
    Okay, first of: I know that there are multiple threads discussing the shader variants compiling just hanging for a long time, but this is not the case here.

    I'm using Unity 2018.4.20f1 (building things for VRChat, so this specific version is required) on Linux. Everything was working fine before until yesterday.

    Now when I'm trying to build & publish an avatar or a world from any previously working project, Unity starts to compile shader variants and will start to freeze at random shaders (or at least I couldn't identify any pattern yet).

    When observing the UnityShaderCompiler child processes, they are all running at 100% CPU while the compile is running. At the moment the compiler freezes, all those child processes go down to 0% CPU usage. Occasionally, the Unity parent process itself would go up to maybe 5% and then go down to 0% again. I assume its trying to reach the stuck UnityShaderCompiler children. Trying to kill them will just result in them being <defunct>, and I'll have to kill the parent Unity process to get rid of them.

    There were no changes made to those projects, so I'm not sure what caused the new behavior. I tried playing around with the build settings, and for one build the shader variant compiling actually went through (and that very quickly), but I could not reproduce that success again.

    Looking at the log files of the UnityShaderCompilers, I only see this for 11 child processes:
    Code (csharp):
    1. Base path: /home/user/Unity/Hub/Editor/2018.4.20f1/Editor/Data
    2. Cmd: initializeCompiler
    Only the first process contains actual log entries, with the last one before it gets stuck being:

    Code (csharp):
    1. Cmd: initializeCompiler
    2. Cmd: compileSnippet
    3.   api=15 type=0 insize=1878 outsize=3001 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR ok=1
    4. Cmd: compileSnippet
    5.   api=15 type=1 insize=1878 outsize=0 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR ok=1
    By the way, I'm only using the "Standard" Unity shader and nothing else.
     
    Last edited: Jul 9, 2020
  2. dasprid

    dasprid

    Joined:
    Jun 22, 2020
    Posts:
    4
    Update on the situation: I went through each individual material, disabled them all, and then tried compiling by activating one after another. Eventually the very last material was the one causing the problem. It was equal to the others, except that it had a roughness texture. After removing that one, the build worked flawlessly. With it enabled, Unity will just freeze when trying to compile it.
     
  3. dasprid

    dasprid

    Joined:
    Jun 22, 2020
    Posts:
    4
    Another update: that only helped once – a second build fails again.
     
  4. Roliga

    Roliga

    Joined:
    Dec 11, 2019
    Posts:
    1
    Did you ever find any clues what the problem might be here? I'm having the same issue here.

    Only "workaround" I found has been to first build a scene with only a couple of materials which works fine, then afterwards build my actual scene which then magically works until I have to change something on my materials, then it breaks again.
     
  5. ValiZ

    ValiZ

    Joined:
    Nov 23, 2017
    Posts:
    2
    Hello! I don't know if this is the same problem, but i had unity always freezing when tried to select the shader dropdown.
    What worked for me was to go into my project folder/Library and delete the file called ShaderCache.I dind't knew why my project was getting so big every time, without adding any new assets or when in fact my project is a small one.Looks like the ShaderCache file was geeting bigger every time when i tried to modify a material, it was 14gb.After deleting that, unity works normally and i am able to change the materials or shaders properties as usual.
     
    brinca likes this.
  6. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    33
    I can confirm that deleting the `Library/ShaderCache` folder solves the problem... I was struck with this issue in the Linux build, after converting from the built-in RP to the URP, and this solved it.
     
    lejomarin likes this.
  7. burningman2k12

    burningman2k12

    Joined:
    Nov 24, 2012
    Posts:
    5
    i can say that i just started having this same issue today with unity 2019 and the latest 2020 version. this fix doesnt seem to work with this version though. it sits with the on hold busy window.
     
  8. alek3tt

    alek3tt

    Joined:
    Nov 11, 2016
    Posts:
    5
    Player -> Other -> Keep Loaded Shaders Alive uncheck then check back again if needed. That resolved the problem for me.