UE4 "Compiling Shaders" is super slow

I found that turning off “Live Nodes” and “Live Update” can speed up responsiveness. That’s probably not what you’re complaining about, but it definitely makes things easier. Also, don’t have the asset browser window open and visible?

Just throwing things out there, not sure it will help.
G’luck!

Some quick things that come to mind

-What hardware are you using? Is there any chance that your drivers are outdated?
-Have you tried creating a new empty project? See if the issue persists?
-If you have multiple instances of the editor open, it might slow down a lot.
-On what version of unreal are you working?

So are we talking about compilation or just applying changes? Is it the textbox on the bottom right saying recompiling shaders? -there is a known bug on one of the versions of unreal causing recompilation of every shader on change-

I’ll do my best to answer:

  • Hardware: New computer on the higher end of things, with all current drivers
  • Haven’t tried a new empty project. I’ve been working from a fairly well-established project. I’ll give this one a try
  • I generally don’t work with multiple instances open in the editor
  • Running on Unreal version 4.16. As I’m typing that, I realize I may want to try a newer version.

Yes, there is a text box at the bottom right that says “Compiling Shaders.” Happens every time I apply changes. Is this the known bug you’re referring to? If so, I’ll switch to a newer version asap!

Thanks for the tips. When I don’t need those features, I’ll be sure to close them/toggle them off.

yeah, sounds like something might be wrong here - just changing params should be basically instant.

here’s another performance gotcha - in the content browser there’s an option for real time preview, i found that was costing my like 30% of my frame rate the other day…

2 Likes

There was a known issue in 4.1 that was quite similar to what you are describing.
it should have been fixed in 4.1.1 though, so its probably not exactly the same thing.

It shouldn’t acctualy have to compile the shader unless you specify it to recompile out of date ones

I haven’t yet found an option to automaticaly recompile out of date shaders, and for as far as I’ve understood, you need to mod the engine to acctualy allow for full recompilations of the shader library.

You’re not going crazy Jason. I deal with the same problem daily. And I’m on a Macbook Pro so I don’t have the benefit of a hefty multi core machine. At The Coalition they wrote a bunch of custom code to speed up compiling by caching as much as possible.

I don’t have any suggestions other than what’s already been said but I’ll see what I can find out next week and get back to you.

1 Like

Sometimes it does take a lil while, yeah! Have you taken a look at the “usage” tab on the material settings? Each extra option there adds to the compilation time. What I can suggest you is placing a static mesh like a sphere or a plane on your scene and using Scalar and Vector parameters as Tharle mentioned above. They take a moment to update on the material viewport but they’re faster on the main editor viewport. Fancy translucency methods also seem to take much longer for me.

Okay, so I just installed a fresh Unreal version: 4.17.2. I opened the simple side-scrolling platformer project. After browsing around for a bit, the same “Compiling Shaders” message appeared in the bottom right, with the number “208” next to it. It hung around for about 20-30 seconds, counting down. What’s happening here? There’s literally one, maybe two, simple grey materials in the entire project. @imbueFX any thoughts?

When compiling the shaders, check the priority of the process in the task manager. I have Win10 put it small, which significantly slows down the process. I decided by setting the value to above average using the program Anvir Task Manager.

Right, the first time you open a project it should compile the shaders you need, this might take a while but one should be able to navigate the engine while that is happening. After that, however, complete compilation should not be necessary.

This sounds like a bug, in which case you would probably have more luck finding someone from epic.

You could also try asking unreal slack or similar group if someone has/had similar issues.

Good luck

It’s been a while for me, but in my experience the shaders will only compile again if you make a change somewhere that requires a recompile.
One thing to note about UE4 shaders is the difference between a “Master” material and a material “Instance.”

When you create a new shader you’re creating a “Master” material, meaning they’re base level shaders. Making almost any node changes beyond scalar or vector parameter changes here will require a recompile.

However, if you create a material instance from a master material you can adjust “most” of the parameters without forcing a re-compile. That’s why, as @tharlevfx mentioned it’s always good to build Scalar and Vector parameters into your master materials so that you can make many instances from that one base shader and have control over their parameters without re-compiling.

Some things will always require a re-compile though such as Changing Blend Modes or Lit Options.

There are also some options in the menus that control re-compiling. Your issue could be as simple as a check box, but I’m not up to speed enough with the latest UE4 to be certain.

I just launched a recently updated project for the first time, and it had to recompile the shaders. It started at 3000 and worked down to 0 at about 10-20 per second, which seems to be about average between my computers and projects.

Even if you only have a single material, if it’s used by particles, skeletal meshes and all sorts of stuff, it requires extra compilation per usage. Usually your first time launching it takes a bit longer, and then it’s faster from there on unless you change some serious stuff (like switching from deferred to forward renderer etc).

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