What It Means & How to Fix It
🧠 Why You’re Seeing This Error
C4005 means a macro (usually via #define
) is being defined more than once — without using #undef
or proper guard logic.
In UE5, this can happen when:
- You define the same macro in multiple files
- You include two headers that both define the same macro
- You redefine an engine/platform macro by accident (like
check
,TEXT
, orPI
)
💥 Example Error Message
error C4005: 'MY_MACRO': macro redefinition
🛠️ Example Code
#define MY_MACRO 1
#define MY_MACRO 2 // ❌ C4005: Redefinition
✅ How to Fix C4005 in UE5 – Step-by-Step
✔️ 1. Use #ifndef
or #pragma once
in Headers
If you’re defining macros in headers, always guard them.
Fix:
#ifndef MY_MACRO
#define MY_MACRO 1
#endif
Or just ensure your file uses:
#pragma once
✔️ 2. Use #undef
Before Redefining
If you must redefine a macro (rare), explicitly #undef
it first.
Fix:
#undef MY_MACRO
#define MY_MACRO 2
✔️ 3. Avoid Redefining Engine Macros
UE5 has a lot of built-in macros like check
, PI
, TEXT
, etc. Redefining them will cause chaos.
Never do this:
#define PI 3.14 // ❌ UE5 already defines PI
✅ Summary: How to Fix C4005 in UE5
Cause | Fix Example |
---|---|
Defining the same macro twice | Use #ifndef , #pragma once , or #undef |
Including headers with clashing macros | Remove duplicate includes or guard properly |
Redefining engine macros | Avoid overriding UE macros like PI , TEXT , etc. |