UE4 "Compiling Shaders" is super slow

i dont know how . but WOW

1 Like

Just checked it in 4.22. Works like a charm. What a discovery! Thanks @Travis :black_heart:

1 Like

See this is the good part about unreal, Unreal packs all those instructions and tries to merge most of them in the least amount possible. When you introduce things like a static parameter switch or a parameter boolean, The moment you use any of the two the code of the whole shader changes taking a completely different path and it needs to compile again.

Parameters are nice, I think the worst compile i had to deal with was the lighting mode for Surface forwardshading where it literaly takes ages to recompile.

A few things to note, Local derived caches are great, Use them.
First time opening a project or an upgrade will force a recompile.

PS: Everything you tick in the material settings literally introduces new code to the file, Think of it as a standard text where you just added new lines for a new case, Lets say two sided or a different lighting mode, Or supported by static lighting and so on, At least thats how i understand it @Bruno

I had this issue but found the solution for it here:

  1. Open the file “C:\Program Files\Epic Games\UE_4.XX\Engine\Config\ConsoleVariables.ini” in any text editor.
  2. Find the line “; r.XGEShaderCompile = 0” and remove the “;” at the beginning of the line and delete it.
  3. Then just restart the editor.
3 Likes

Holy f***ing hell it actually works. You’re a literal life saver, tysm. Also, how is the coding behind UE4 so absurd that giving focus to another running task and taking away potential RAM from the actual engine speeds up compile rather than slowing it down?

The XGE shader compile stuff is meant to be for swarm shader compiling with multiple machines, so no idea why it would be ‘on’ by default.

Anyway, one thing I wanted to mention here is: Shader compile times rapidly decrease with number of cores. If you can afford a Threadripper, it will shred through shader compiling like there is no tomorrow. If you can’t afford a Threadripper, get a CPU with more cores, rather than more CPU power.
Just wanted to mention this as it seemed revevant :slight_smile:

So I was having issues with 4.27 hanging up and stopping the shader compile after a few hundred (It would just compile a few and then just hang on that number). This was also causing a crash every time I tried to save something with the “Compiling Shaders ####” still on screen, even though the compiler was no longer running in the task manager.

I found this really helpful post that massively increased my shader compiles, hopefully it helps others as well. I don’t know what other versions this fix will work for, but it worked for 4.27 for me

The main post talks about talks about setting app priorities in the task manager, but this comment is about adjusting the priority of the shader compiler in the BaseEngine.ini file. Mine was set to -1, so I swapped it to 2, saved, and restarted my project. Not only did it fix my compiler hang up, but sped the initial shader compile up like a charm.

2 Likes