Search Unity

All shaders fails to open source file custom *.cginc

Discussion in 'Linux' started by lassade, Mar 23, 2018.

  1. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    127
    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
     
  2. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    256
    I am having this issue too on build & run for Windows
     
    gogogo_unity likes this.
  3. drumit84

    drumit84

    Joined:
    Aug 25, 2014
    Posts:
    1
    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.
     
    RiverHu, dccoo, alecfilios and 7 others like this.
  4. ian_unity431

    ian_unity431

    Joined:
    Oct 12, 2018
    Posts:
    10
    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.
     
  5. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    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 :))
     
  6. HypeVR

    HypeVR

    Joined:
    Aug 28, 2018
    Posts:
    11
    Right click the shader and reimport fixed my problem.
     
  7. re-cheid

    re-cheid

    Joined:
    Apr 10, 2017
    Posts:
    34
    Had the same problem, reimport fixed this but make sure Visual Studio is closed while reimporting
     
    LaurieAnnis, Radivarig, MaZy and 2 others like this.
  8. HunterAhlquist

    HunterAhlquist

    Joined:
    Oct 6, 2013
    Posts:
    132
    Re-importing hasn't worked for me.
     
  9. zl2685787271

    zl2685787271

    Joined:
    Sep 29, 2020
    Posts:
    1
    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++.
     
    ESludden likes this.
  10. ESludden

    ESludden

    Joined:
    Aug 27, 2012
    Posts:
    19
    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)
     
    MaZy and cihad_unity like this.
  11. gaiastellar

    gaiastellar

    Joined:
    Nov 8, 2013
    Posts:
    57
    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 RWTexture2D<float>4 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?
     
  12. Qlymaxis

    Qlymaxis

    Joined:
    Jul 24, 2020
    Posts:
    1
    Re-importing fixed the issue thank you so much I was getting mad :D
     
    snow802 likes this.
  13. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    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)
    https://dkrevel.com/failed-to-open-source-file/
     
    StellarVeil likes this.
  14. OlivierMorland

    OlivierMorland

    Joined:
    Sep 24, 2021
    Posts:
    8
    I needed to do two things to fix this issue:
    1. Re-importing the shader.
    2. Comment out and then uncomment the import .cginc line to reload the shader scripts which are generating the error message.
     
  15. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    205
    PrimalCoder likes this.
  16. GoblinGameWorks

    GoblinGameWorks

    Joined:
    Sep 14, 2019
    Posts:
    13
    This worked for me as well, thanks.
     
  17. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Even restarting Unity didn't work but reimporting the shader did. 2022.1.11f1 btw. still the same issue with moving those files around.
     
  18. Glazic

    Glazic

    Joined:
    Dec 22, 2017
    Posts:
    7
    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.
     
  19. jasonvoorhes5

    jasonvoorhes5

    Joined:
    Feb 26, 2022
    Posts:
    2
    My CGIncludes were detected after I deleted the .meta files of the shaders in the project. Maybe it will work for you.
     
  20. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    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 :-(

    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" :)
     
    JonnyG7 likes this.
  21. michaalwronaa

    michaalwronaa

    Joined:
    Aug 20, 2023
    Posts:
    1
    In my case everything worked and compiled fine but I had strange errors. It turned out that VS doesn't understand .shader format and I had to install shaderlabVS extension.

    upload_2024-1-10_12-11-54.png
     
  22. frankes166

    frankes166

    Joined:
    Dec 21, 2020
    Posts:
    1
    Reimporting the shader or deleting library folder didn't work for me. In my case one of the shaders files (UnityStandardUtils.cginc) was corrupted and that's why Unity couldn't access it. I couldn't delete it or move it out of the folder because it was corrupted due to the issue with my disc C. I had to scan my disc C and then I was able to delete this file. Then I found the exact same file in the same folder of the different Unity version and just copied and pasted this file into my folder. This fixed the issue.

    If reimporting the shader doesn't work for you. Check if you don't have corrupted files in your shaders folder. You will now it is corrupted if you cant move it outside of the folder. It will tell you that there is an error because file is corrupted.