Quick answer: The function name in the node must exactly match the HLSL function. Output parameter names must match the node’s output slots. Use void FunctionName_float(in, out) naming convention. File must be .hlsl in Assets/.

Here is how to fix Unity Shader Graph Custom Function not compiling. You create a Custom Function node, point it to your .hlsl file, set the function name, add inputs and outputs. The node shows a red error bar — just “Shader Error.” Custom Function is powerful but strict about naming conventions that the UI does not explain.

The Symptom

Custom Function node shows a compile error in Shader Graph. Material preview is pink. Other standard nodes compile fine.

What Causes This

Function signature mismatch. Shader Graph generates a call with specific parameter names based on your node’s input/output definitions. If the HLSL function has different parameter names, the generated call does not match.

Missing precision suffix. Custom Functions must use precision-suffixed naming: MyFunction_float or MyFunction_half. Shader Graph calls the variant matching the graph’s precision.

File not found. The Source field must point to a .hlsl file inside Assets/ or Packages/. Files in Editor/ folders do not resolve.

Output parameter not out. HLSL output parameters must use the out keyword.

The Fix

Step 1: Match function signature exactly. If your node has inputs A (float) and B (float3) and output Result (float3):

void MyCustom_float(float A, float3 B, out float3 Result)
{
    Result = B * A;
}

Function name = node’s Function field + “_float”. Input names match node inputs. Output names match node outputs. All case-sensitive.

Step 2: Provide both precision variants.

void MyCustom_float(float A, float3 B, out float3 Result) { Result = B * A; }
void MyCustom_half(half A, half3 B, out half3 Result) { Result = B * A; }

If the graph switches to half precision (mobile), it calls _half. Missing it causes compile failure on mobile builds.

Step 3: Use String mode for simple functions. Instead of a file, select Type = String and write the body inline: Result = A * B; String mode wraps your code in the correct function signature automatically.

Step 4: Verify file path. The Source field should show the .hlsl file as a Unity asset reference. If it shows “None,” the file is not recognized. Ensure file extension is .hlsl and it is inside Assets/.

Debugging

Select the material. In the Inspector, click “Edit Shader” or view the generated shader code. Search for your function name. The compiler error lines tell you exactly which parameter is wrong.

“Custom Function is string-exact. Function name, parameter names, precision suffix — all must match the node definition character for character.”

Related Issues

For pink materials, see Unity Pink or Magenta Materials. For preview issues, Shader Graph Preview Black Screen.

FunctionName_float with matching params. Both precision variants. File in Assets/.