Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Unable to open #includes in ShaderGraph with CustomFunction

Discussion in 'Shader Graph' started by SpikeEscape, Jan 13, 2022.

  1. SpikeEscape

    SpikeEscape

    Joined:
    Mar 14, 2019
    Posts:
    5
    Hello all, I started off following a tutorial to adjust light attenuation with shaders,

    I followed it to the letter and eventually found my references to the struct Light or any function inside of URP's Lighting.hlsl caused Shadergraph to produce the error: "Unrecognized Identifier".

    Which was odd because most of the includes of URP are included by default when you make a new ShaderGraph file, I checked the comments of the tutorial and the main advice was to check all my graph settings and make sure target was set to "Universal" and they all correct and compiling for URP.

    I attempted to grab the reference manually by including ShaderLibrary/Lighting.hlsl at the top of my CustomFunction however that produced more errors in the console log stating that I was "Redefining _Time" in the Master file.

    I was doing this in Unity 2020.3.25f1 with URP 10.7.0, I've now swapped to an empty project in 2021.2 and URP 12.1 and now on top of the "Unrecognized Identifier: Light" ShaderGraph error, I'm now also getting console errors saying:

    "[Worker0] Shader error in 'Shader Graphs/LightingTest': Couldn't open include file 'Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl'. at line 400"

    I'm getting 12 of these errors with various ShaderLibary/*filename*.hlsl at line *etc*

    So something is interfering with the ability to execute these includes, and the above error of "Redefining _Time" was almost definitely a result of including the same file twice. More googling and I found someone else having these "Couldn't open include file" errors however they fixed it by changing the "Override Preprocessor" setting on their raw shader file, which I cannot do since I'm using ShaderGraph.

    Any new troubleshooting advice is greatly appreciated, I've been doing this for hours and I feel like I'm running low on resources to google haha
     
  2. SpikeEscape

    SpikeEscape

    Joined:
    Mar 14, 2019
    Posts:
    5
    Hey all, I have tried uninstalling URP, deleting the package cache in my appdata/local/unity folder and reinstalling, I've made a tiny piece of HLSL to test if it was working and now it is giving me a very odd "Unexpected Bracket" error, I'm now more confident that this is a genuine Unity error that will have to be patched.

    Incase you can't read it in the screenshot, it says found on line 163, which must be referring to some other file which is *included* in the generated .shader file, cause obviously the hlsl isn't that long and I checked inside the raw .shader file of my unlit shadergraph and there isn't a bracket to be found on or near line 163.
     

    Attached Files:

  3. SpikeEscape

    SpikeEscape

    Joined:
    Mar 14, 2019
    Posts:
    5
    Hey all, I've since figured out how this bug was working, I had my unity program installed to the same drive as my OS, and saved all of my unity projects onto a separate storage drive, I was having read-write errors on the automatically #include's of shadergraph .shader files because it could not access the .hlsl files in-between different drives.

    The fix was to copy my project files over to my C:// drive and it was fixed.