- Home /
How to force the compilation of a shader in Unity?
From time to time when writing shaders with CG language in it I get normal errors like syntax errors or some others that everyone makes during normal coding, but sometimes Unity stops recompiling my shaders and keeps a older version compiled ("Open Compiled Shader" option) and does not recompile it until I erase completely the shader and the material assigned and create it from zero with the same shader code.
Is there a way to force a recompilation of the shader? Maybe erasing something in the Assets folder or any other place?
Answer by Aras · Jun 30, 2010 at 06:08 AM
Does right clicking on the shader and doing "Reimport" help?
Answer by Kelvin 2 · Jul 10, 2010 at 06:00 PM
Right click the file and Select "Reimport", this is the solution provided by the Unity team.
Answer by andeeee · Feb 09, 2010 at 05:00 PM
Does this happen when you open the file from the text editor's recent items menu, or when you open the file from the desktop? Unity doesn't always track files if they weren't opened from within Unity. Try closing open shader files and reopening them from Unity.
I did opened them from Unity, the only thing that does the trick according to the Unity $$anonymous$$m themselves is to right click the shader file in Unity and "Reimport" them.
Answer by lgarczyn · Mar 19, 2020 at 11:53 PM
Since this is a popular question, I'll add another possibility:
Two shaders can share the same name, with no warning from Unity. Make sure you are editing the correct shader.
Answer by randomdragon · Aug 30, 2021 at 01:31 PM
THIS WON'T WORK for a compute shader file that includes only constant variables data. Such a data file won't recompile even if you reimport it. The only way to update this kind of file that I find for now is to explicitly change the name of the variable you use in both the compute shader and data file and save them. I suppose this is a unity bug that needs fixing.
My unity version: 2020.3.12f1c1