Super simple question, I’m sure. I’m throwing an error that the maximum number of shader keywords has been exceeded. I assume this is because I have quite a few shader assets in my project with different naming conventions (wrong?) I’m having some problems getting some shaders to work properly, which I am again assuming is because of this problem (?). Am I to assume that the best course of action is to begin removing unused shaders in the hope that I’ll get back under the limit? Thank-you for your time.
Is this really what the error says? Are you sure it’s not “Arithmetic instruction limit exceeded”? Which can be easily fixed by adding
#pragma target x to the shader which is throwing the error, where x is an appropriate shader model, see: Unity - Manual: HLSL in Unity
Thanks for the reply, but the exact error (it throws them for different shaders so it’s not just a skyshop problem, but here’s an example):
Maximum number (64) of shader keywords exceeded, keyword MARMO_BOX_PROJECTION_OFF will be ignored
UnityEngine.Shader:EnableKeyword(String)
mset.Sky:Apply(Renderer) (at Assets/Marmoset/Skyshop/Script/Sky.cs:116)
mset.Sky:Apply() (at Assets/Marmoset/Skyshop/Script/Sky.cs:88)
mset.Sky:OnDrawGizmos() (at Assets/Marmoset/Skyshop/Script/Sky.cs:398)
UnityEditor.DockArea:OnGUI()
Interesting. Maybe someone from UT can comment on this. Summon Aras.
Also, I didn’t see the keyword limit mentioned in either the documentation nor the unite talk from 2012. In fact, the documentation doesn’t even mention Shader,EnableKeyword. Only Material.EnableKeyword.
Aras put something online where he talks about the problem of having many keywords, but there is no solution for users. http://aras-p.info/texts/files/201301%20Shader%20Pipeline%20in%20Unity.pdf
Maybe you can compile the different shaders by hand instead of relying on keywords? Other than that, yeah, removing unused stuff sounds like your best bet.
Hmm, weird that this doesn’t come up more often, I’m only using a few (3) shader packages and this problem has rendered them unusable. Maybe I’m doing something else wrong…
Just thought I’d chime in and say that this is affecting me as well. The combination of skyshop, sunshine!, and tc particles seems to be the cause in my case. I just can’t run those three packages a scene without this happening:\
Looks like I’m also running into this issue now, experimenting with a few shader Assets and now receiving a lot of errors.
Edit 1) Any chance we could get a response from Unity as to whether this limit will be increased in Unity 4.6 or 5.0? Sadly I’m now having to remove some of the best shader assets due to this issue that I planned on using.
Edit 2) Fixed this issue by removing unused Shader Assets from my project. Not very happy considering they were Assets purchased before running into this issue. Unity adds in every shader with multi_compile regardless of whether they are actually used in the project or not. So it looks like unused shaders can end up going over the 64 limit and causing shaders that are being used to stop working. ![]()
Same here, using Marmoset Skyshop and AdvancedFoliageShaders.
Any help?
According to Aras, Unity 5 will very likely increase the limit to 128.
Nice, but this seems to be a bug for me. I had no problems with the same project on 4.5.3.
An interesting part is, that when I re-opened the error-causing project in 4.5.3 again, it also causes these errors there.
Fortunately I dublicated the whole project before upgrading. With the copied folder everything is fine in 4.5.3 again.
Looks like 4.5.5 is “contaminating” a project…
Same thing happened on 4.6.1. Using Marmoset RTPv3.1 ,AdvancedFoliageShaders and a lot of different shaders for postprocessing.
I have added SunShaft Image effect to the camera and modified it. I have added SunShaftComposite shader new uniform:
uniform float _depthThreshold
After that I received an error in RTPv3.1:
Maximum number (64) of shader keywords exceeded, keyword RTP_POM_SHADING_MED
Maximum number (64) of shader keywords exceeded, keyword RTP_POM_SHADING_HI
It still working but with default Terrain shader.
I removed my uniform from SunShaftComposite shader and RTPv3.1 started working just fine, but still have an error in console.
After I restarted Unity Editor, the error disappeared from console.
Again I added new uniform to SunShaftComposite shader but with another name:
uniform float _depthShaft
And there is no error and everything works!
Any ideas what caused it?
You’ve just hit the Unity limit for the maximum amount of keywords.
As for your issue and fix asemenov, I can only assume that something else other than uniform was changed or activated, as the two are not related. Restarting Unity may have cleared something it had else that freed up those keywords.
Thanks!
Yeah, seems so.
Before I changed SunShaft second time and Unity recompiled it, Unity Editor restart didn’t help.
It seems that Unity rearranged keywords somehow after first change of Sunshaft, and fixed it back after second change.
I think that I almost reached keywords limit.
This is still an issue in 2016.
Shaders that are not used should not be counted
Still a problem with 128 keywords. Using the current best of breed shaders available on Asset Store like TextMesh Pro and Uber together results in a broken project. How do we fix this? I posted about this here: http://forum.unity3d.com/threads/solved-64-keyword-limit-questions.252750/
PLEASEEEE FIX!!
Maximum number (256) of shader keywords exceeded… Unity 2018. Why there is such a limit in the first place? This is ridiculous!
Yea I ran into the same problem after installing light weight render pipeline and the High Def one from the package manager. uninstalled them.
I have the same problem
You will find having a ton of unused materials will cause this, so remove all your unused materials. In addition most 3rd party shader assets tend to abuse this system a lot.
SRP shouldn’t have these problems because they do not use builtin shaders. So what is happening is you are probably going to have to redo all your materials and remove all your legacy shaders because they do not work on LW or HDRP anyway.