Quick answer: Custom Function Source field expects a path relative to Assets/, with .hlsl extension and forward slashes. Assets/Shaders/MyHelpers.hlsl works; relative or external paths don’t.
Custom Function fails to find the include. Editor preview works (file path is local), build breaks (path resolution differs).
The Symptom
Shader Graph compile error: “Could not open include file.” Editor sometimes works; builds reliably fail.
The Fix
Custom Function node:
Type: File (not String)
Source: Assets/Shaders/MyHelpers.hlsl
Name: MyFunction
Inputs: In Vector3
Outputs: Out Vector3
Path starts at Assets/. Forward slashes. Save the .hlsl in Assets so the path resolves.
Inside the .hlsl:
// Assets/Shaders/MyHelpers.hlsl
void MyFunction_float(float3 In, out float3 Out)
{
Out = normalize(In);
}
Function name plus _float suffix matches what Shader Graph generates as the call.
Sharing Across Projects
Wrap the .hlsl in a Package (custom or git-based). Reference via Packages/com.you.shaders/Helpers.hlsl. Versioned and shared.
Verifying
Build for the target. No include errors. Frame Debugger shows the function in the generated code.
“Path from Assets. .hlsl extension. Function name + suffix. Includes resolve.”
Related Issues
For Shader Graph stencil URP, see stencil URP. For Shader Graph keyword instancing, see keyword instancing.
Path right. Function suffixed. Compiles.