UE4 "Compiling Shaders" is super slow

materials
unreal
ue4

#1

Been teaching myself some UE4 material stuffs lately, and I’m noticing the compile time is annoyingly long whenever I make a change in the material editor, even to a really simple material (and much worse on complex materials). I’ve heard similar complaints from other VFX people, and found a few threads on other forums mentioning it, with Lexeon’s recent response giving me hope that I’m not so crazy:

https://answers.unrealengine.com/questions/409626/compiling-shaders-is-way-too-slow.html

Anybody know how I can fix this, or if it’s a bug, is Epic is working to address the issue?


#2

Really stupid hack, but open the calculator app or something similar and make sure it has focus. Speeds up the compile time a ton for whatever reason. It’ll get through a few thousand in a minute or two


#3

lol. so derpy! the work-arounds we find… :^b


#4

One tip is to make sure you’re using Scalar and Vector Parameters to define the look of your shaders - once its compiled these can be changed as you like without forcing a recompile which makes iterating over the final look much easier.

I basically always set up my materials with params for Tiling, Intensity, Contrast, Colour, etc. etc. then just tweak the numbers once the effect is made.

Also if you’re using a lot of Static Switches that can lead to long compile times - the engine compiles all the possible combinations of switches which gets pretty heavy pretty quickly.


#5

Why do you need to compile that much that it bothers you? Normally materials only need recompiling if they are used in a different context, mesh -> sprite for example. And even that shouldn’t take longer then a few seconds since it’s only partially recompiling it.

Maybe you are forcing the engine to recompile multiple shaders, or there might be a lot of material dependencies which forces adjustments to be made on everything that depends on it?


#6

Would there be any setting to not force the engine to recompile multiple shaders? I can say there aren’t any cross-material dependencies, though some materials are more complex than others. It’s when I’m iterating on a new material, playing around with different nodes that it’s bothering me. Every new hook-up or disconnect triggers a fresh re-compile of the material’s preview, which is a few seconds each time (up to 20-30 seconds at the high end).

True, once I’ve got the materials I want all done, I’ll be good to go. But learning the material system for the first time, or making future tweaks to my materials has a persistent ear-flick effect, rather than giving me the instant iteration feedback I’m accustomed to in other creative development software.


#7

Actually, updating parameters on material instances sometimes has a delay as well. It doesn’t seem to be as long as working in the parent material, but for a complex shader I came across, it was still about 5-10 seconds each time I tweaked a value.

As for static switches, I was noticing in that shader it took significantly longer to compile than the newbie stuff I am playing with. That’s not the most unexpected thing. Seems logical more complex = more time to compile. Still, I’d hate to be the one iterating on that thing.


#8

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!


#9

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-


#10

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!


#11

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


#12

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…


#13

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.


#14

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.


#15

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.


#16

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?


#17

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.


#18

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


#19

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.


#20

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).