1. Home
  2. UE5 Compilation Errors
  3. Shader Compilation Errors
  4. Shader Error: UE5 X3004 – Undeclared Identifier

Shader Error: UE5 X3004 – Undeclared Identifier

What It Means & How to Fix It in UE5


🧠 Why You’re Seeing This Error

This error means the shader compiler tried to use a variable or function name that hasn’t been defined or declared in your shader file (or included files).

In Unreal Engine 5, this usually happens when:

  • You misspelled a variable or function name
  • A needed uniform, buffer, or macro is missing
  • You forgot to include a .usf or .ush file with the needed definitions
  • A preprocessor directive (#if, #define, etc.) blocked something from being declared

💥 Example Error Message

error X3004: undeclared identifier 'LightDirection'

🛠️ Common Shader Scenarios That Cause This

❌ Typo or Misspelled Variable

hCopyEditfloat3 result = LightDirektion; // ← typo: should be LightDirection

❌ Missing Include File

hCopyEdit// You're using a function like TransformWorldToClip()
TransformWorldToClip(VertexPosition); // ❌ But Common.usf isn't included

❌ Variable Is Inside a Disabled #if Block

#if USE_LIGHTING
float3 LightColor = float3(1,1,1);
#endif

float3 Output = LightColor * Albedo; // ❌ LightColor may not exist if USE_LIGHTING is 0

✅ How to Fix X3004 in UE5 – Step-by-Step


✔️ 1. Check for Typos or Case-Sensitive Mistakes

VariableName ≠ variablename ≠ VARIABLEname

HLSL is case-sensitive, unlike Blueprint variable names.


✔️ 2. Verify That the Variable or Function Is Defined

Search the file or included files for the identifier. If it’s not found:

- Declare it manually
- Or include the proper `.ush` / `.usf` file that contains it

Example:

#include "/Engine/Private/Common.ush"

✔️ 3. Make Sure Preprocessor Conditions Don’t Block It

Check if the variable is inside a conditional block like:

#if USE_SHADOWS
float ShadowAmount;
#endif

If USE_SHADOWS is undefined or 0, then ShadowAmount is never declared.


✔️ 4. Review Included Files and Their Order

If you’re using custom shaders:

- Ensure required files are included (Common.ush, ScreenPass.ush, etc.)
- Avoid shadowing variable names with redefinitions

✅ Summary: How to Fix “error X3004: undeclared identifier” in UE5

CauseFix Example
Variable/function was never declaredDefine it, or include a file where it is declared
Misspelled nameCorrect the spelling and casing
Macro or preprocessor condition excluded itCheck for missing #define or #if blocks
Missing include fileAdd #include for needed shader utility files
Was this article helpful to you? Yes No

How can we help?