All shaders fails to open source file custom *.cginc

Well guess the title says it all no matter what shader I have in the Assets folder if includes a custom *.cginc it will fail to compile. Funny thing is that I’m having this error with shaders of both PostProcessingStack and TextMesh Pro packages.

Any ideas?

Using 2017.3.0f1 on Fedora 26

I am having this issue too on build & run for Windows

1 Like

Make sure your shader file if it includes other files has the right folder structure. I ran into this also after I moved my files around into different folders. It is basically breaking the connection between the custom files.

IE: In my shader file I include a resource file. I used to just have it here in the root like this.

#include “/CustomShaderFile.cginc”

So when I moved my custom shader into a new folder I had to change the structure so it looked in the right folder.
#include “…/ShadersFolder/CustomShaderFile.cginc”

Hope this helps.

11 Likes

Also, if you re-named the .cginc file and you know the path of to the include is correct in your shader, try closing Unity and re-opening the project. That fixed my issue.

3 Likes

Same bug still in 2019.2+ - if you reference a custom .cginc file and move either the .cginc, or the shader, to a new subfolder then you get a bunch of fake errors about missing core CGInc files (which are definitely NOT missing), and the Inspector shows a long list of errors for all the core CGI files that Unity now claims it cannot find (although obviously it can, because they haven’t moved :))

Right click the shader and reimport fixed my problem.

37 Likes

Had the same problem, reimport fixed this but make sure Visual Studio is closed while reimporting

5 Likes

Re-importing hasn’t worked for me.

i’d like to say that after 3 times creating new projects and reimporting, my cginc finally worked. I’m not sure what really repairs that. I have even changed the endcoding of that source by notepad++.

1 Like

Can confirm that ‘Reimport’ works, but not on the first try, takes several attempts like starting a car in winter. (I reimport with Visual Studio off)

2 Likes

hi,
im having this trouble with an #include in a compute shader the line is #include “Assets/FastNoiseLite”
that should work right? im just teaching myself compute shaders and im am getting quite a few weird errors, like it complains that the line RWTexture2D4 texturename is wrong, so i just delete and retype it and now its fine!! i mean really!!! is this just really broken or what?
some code that was working before, i added some more code, it didnt work so i just removed it, and now the the original code isnt working either, even though its exactly the same as it was before…

is anyone else having any trouble just getting basic stuff to work?

Re-importing fixed the issue thank you so much I was getting mad :smile:

1 Like

I would like to add one confusing pitfall.

If one of the user include fails, it output failure message about built-in also. (Thus those misleading error message about built-in cginc missing, which is outside user’s responsibility)

For example, if you have shader “Assets/Shaders/a.shader” which has
CGINCLUDE
and another custom include line that says
#include "Extra/ColorUtil.cginc" (expects Assets/Shaders/Extra/ColorUtil.cginc)
and you dont have it. You get complain about built-in also!

Credit this finding to this blog (Japanese)

1 Like

I needed to do two things to fix this issue:

  • Re-importing the shader.
  • Comment out and then uncomment the import .cginc line to reload the shader scripts which are generating the error message.
4 Likes

It looks like this issue is related to Unity Issue Tracker - ShaderGraph reference to HLSL file is lost after moving it to a different folder.

I had this issue only after moving a folder. I am on 2020.3.24f1 though and shouldn’t have this issue of losing references when moving folder with shaders. Reimporting did solve it for me too, though.

1 Like

This worked for me as well, thanks.

Even restarting Unity didn’t work but reimporting the shader did. 2022.1.11f1 btw. still the same issue with moving those files around.

I have the same problem with ProBuilder.
Shader error in ‘Hidden/ProBuilder/VertexPicker’: Couldn’t open include file ‘ProBuilderCG.cginc’. at line 31
Shader error in ‘Hidden/ProBuilder/EdgePicker’: Couldn’t open include file ‘ProBuilderCG.cginc’. at line 29
If i change line
#include “ProBuilderCG.cginc”
to
#include “…/Shader/ProBuilderCG.cginc”
error disappear, but then warning says:
The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.unity.probuilder/Content/Shader/VertexPicker.shader
The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.unity.probuilder/Content/Shader/VertexPicker.shader
and its return to #include “ProBuilderCG.cginc”
Re-import doesn’t help. It looks like a bug.
Only helps to move ProBuilderCG.cginc to {unity install path}/Data/CGIncludes/ but its very bad solution to move custom file from package to Built-in shader files folder.

My CGIncludes were detected after I deleted the .meta files of the shaders in the project. Maybe it will work for you.

i had the same problem, but in editor it didnt matter, as i was not using the shaders (where in a unused package) i could start “play” mode.

but build failed (some times! not always), and then REIMPORT did not help me.

what did help me IN EDITOR, was deleting .meta files (in a folder with many shaders),
but didnt work in a folder with few shaders.

but when building the errors came back :frowning:

BUT what helped finally was editing the shader files that did #include “filename.cginc” which referenced correct cginc files placed in same folder(s) as shader(s) to become #include “./filename.cginc” :slight_smile:

1 Like