Quick answer: Unreal Header Tool stops the build when any #include appears below #include "YourFile.generated.h". Move the offending include above that line so the generated header is the last include in the file, or replace it with a forward declaration and include the real header in the .cpp. Nothing needs to be deleted or regenerated for this error; the next build re-runs the header tool.
This is one of the first build errors a new Unreal C++ programmer meets, and usually they did not type the line that caused it. An editor quick-fix, a paste or a merge dropped an include one line too low, and Unreal Header Tool (UHT) refuses to continue. The fix takes ten seconds. The reason for the rule is worth two minutes, because the same mechanism explains several other header errors that tend to arrive in the same week. Those are listed further down with their fixes, followed by a header layout you can copy.
- The exact message
- Why the generated header has to be last
- How the include ends up there
- The fix
- The header errors that arrive with it
- A header layout that avoids all of them
- When to delete Intermediate and regenerate project files
- Where Bugnet fits, and where it does not
- Related guides
- Frequently asked questions
The exact message
Pickup.h(8) : error : #include found after .generated.h file - the .generated.h file should always be the last #include in a header
The file and line number point at the include that is in the wrong place, not at the generated include. The prefix format differs slightly between UE4 and UE5 (Pickup.h(8): Error: on the newer header tool); the sentence is the same. It comes from UHT, so it appears before any C++ is compiled, both from the IDE and from the editor’s compile button.
Why the generated header has to be last
Pickup.generated.h is not an ordinary header. UHT writes it into Intermediate on every build, and it contains macros only: the reflection boilerplate for each class, struct and enum in Pickup.h. GENERATED_BODY() finds the right one by gluing together a file identifier and its own line number. Simplified from the engine’s ObjectMacros.h:
#define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);
The last thing a generated header does is redefine CURRENT_FILE_ID to its own file. If another Unreal header is included afterwards, it pulls in its generated header, CURRENT_FILE_ID now names that other file, and the GENERATED_BODY() in your class expands to a macro that does not exist. Rather than let the compiler print a page of macro errors, UHT checks the order up front and stops.
The same mechanism explains a harmless annoyance: after you add lines above GENERATED_BODY(), the IDE may underline it in red until the next build, because the generated macro still carries the old line number.
How the include ends up there
- An IDE quick action or code assistant added it. You used a type, accepted “add include”, and the tool appended the line to the end of the include block. Tools that are not Unreal-aware do this consistently.
- A pasted line. You copied an include from another file and put it under the last one.
- A merge. Both branches added includes at the bottom of the block and the resolved file kept one on each side of the generated include.
- A conditional include added below the block:
#if WITH_EDITOR, an include,#endif. - An include further down the file, such as an
.inlfile at the bottom or an include between two classes. The rule covers the whole header, not only the top.
The fix
Broken:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
#include "Components/SphereComponent.h" // added below: error
Fixed by moving it:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SphereComponent.h"
#include "Pickup.generated.h" // last
Better, when the header only holds a pointer to the type:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
class USphereComponent; // forward declaration, no include
with #include "Components/SphereComponent.h" in Pickup.cpp. A forward declaration is not an include, so it may sit below the generated header. Every include in a header is paid for by each file that includes that header, and two headers that include each other produce errors that look nothing like their cause, so keep header includes to what the header needs by value: base classes, structs and enums used as members. Which uses need the full include is covered in Unrecognized type - type must be a UCLASS, USTRUCT, UENUM.
A conditional include moves up as a block, #if and #endif included. An .inl at the bottom has to move above the generated include or into the .cpp.
The header errors that arrive with it
Fixing the include order often uncovers the next problem in the same file. The usual ones:
| What you see | Cause | Fix |
|---|---|---|
UHT: Expected an include at the top of the header, naming #include "Pickup.generated.h" | The generated include is missing, or still carries the old name after the file was renamed | Add or rename it. The name follows the file, not the class: Enemy.h includes Enemy.generated.h |
fatal error C1083: Cannot open include file: 'Pickup.generated.h' | The header has no UCLASS, USTRUCT or UENUM, so nothing was generated, or the file sits outside a module’s Source folder | Remove the include from plain C++ headers; move the file into the module |
UHT says it expected GENERATED_BODY() at the start of the class, or the compiler reports syntax errors on that line | The macro is missing, misspelled, or shares a line with other code | Put GENERATED_BODY() alone on the first line inside the class or struct |
UHT says the class has an invalid Unreal prefix and names the one it expected, such as AMyActor | Actor classes must start with A, other UObject classes with U, structs with F | Rename the class. If Blueprints already derive from it, add a core redirect |
Syntax errors on the UCLASS() line or the base class name | The header includes nothing that defines the macros or the parent | #include "CoreMinimal.h" first, then the parent class’s header |
LNK2019: unresolved external symbol when another module uses the class | No MYGAME_API between class and the name, so the class is not exported | Add your module’s API macro; see the LNK2019 guide |
Expected Pickup.h to be first header included. (in the .cpp) | The engine enforces include-what-you-use for your module | Make the matching header the first include of the .cpp |
Exact wording of the UHT messages varies between engine versions, which is why some rows above describe the message instead of quoting it. Two of these deserve a note. The missing API macro compiles and runs without complaint for as long as only your own module uses the class, then fails at link time weeks later when a second module or a test target touches it. And the API macro must be the one for the module the file lives in: a header copied from another module with its old OTHERMODULE_API left in place produces DLL import and linkage errors instead.
A header layout that avoids all of them
// Pickup.h
#pragma once
#include "CoreMinimal.h" // 1. core types and macros
#include "GameFramework/Actor.h" // 2. the parent class
#include "ItemData.h" // 3. structs and enums used by value
#include "Pickup.generated.h" // 4. always last, named after this file
class USphereComponent; // pointers: forward declare
class UStaticMeshComponent;
UCLASS()
class MYGAME_API APickup : public AActor
{
GENERATED_BODY()
public:
APickup();
protected:
UPROPERTY(VisibleAnywhere)
TObjectPtr<USphereComponent> Trigger;
UPROPERTY(VisibleAnywhere)
TObjectPtr<UStaticMeshComponent> Mesh;
UPROPERTY(EditAnywhere)
FItemData Item;
};
// Pickup.cpp
#include "Pickup.h" // matching header first
#include "Components/SphereComponent.h"
#include "Components/StaticMeshComponent.h"
TObjectPtr is the UE5 form; in UE4 write USphereComponent*. Creating classes through Tools > New C++ Class in the editor (File > New C++ Class in UE4) gives you this layout with the right prefix, API macro and generated include already in place.
When to delete Intermediate and regenerate project files
Not for the include-order error. UHT runs again on every build, so moving the line is the whole fix. A clean is worth doing when the generated files themselves are stale:
- You renamed, moved or deleted header files and errors now mention
.generated.hor.gen.cppfiles for classes that no longer exist. - You added or removed source files outside the editor and the IDE does not show them.
- You switched engine versions or pulled a branch with a different module layout.
- Close the editor and the IDE.
- Delete the project’s
IntermediateandBinariesfolders, and the same two folders inside each plugin under the project’sPluginsfolder. LeaveContent,Config,SourceandSavedalone. - Right-click the
.uprojectand choose Generate Visual Studio project files. If that entry is missing, see this fix. - Build the Development Editor configuration from the IDE.
The build has passed the header tool once the output prints a line beginning Reflection code generated for and starts compiling .cpp files. Errors after that point are the compiler’s or the linker’s.
Where Bugnet fits, and where it does not
It does not fit here: a header tool error stops the build on your machine and never reaches a player, and Bugnet is a runtime tool. It becomes relevant one step later. Clearing these errors often involves renaming a class or a file, and a rename that compiles can still break the Blueprints and saved assets that referred to the old name, which only shows when the game runs. Bugnet’s Unreal SDK files fatal errors, failed asserts and ensure failures with the engine’s message and recent log lines, and every report carries the game version, so you can see whether a problem began with the build that contained the refactor. Setup is in the getting started guide.
Related guides
- How to Fix “Unrecognized type - type must be a UCLASS, USTRUCT, UENUM, or global delegate” in Unreal
- How to Fix “error LNK2019: unresolved external symbol” in Unreal Engine
- Fix: “Generate Visual Studio Project Files” Missing from the .uproject Right-Click Menu
- How to Fix “Project could not be compiled. Try rebuilding from source manually” in Unreal
- How to Fix “Unable to build while Live Coding is active” in Unreal Engine
Frequently asked questions
Why must the .generated.h file be the last include in an Unreal header?
The generated header defines the macros that GENERATED_BODY expands to, keyed on the current file. Any Unreal header included after it brings its own generated header and changes which file those macros refer to, so Unreal Header Tool rejects the order before compiling.
How do I fix include found after .generated.h file?
Open the header named in the error and move the include on the reported line above the include that ends in .generated.h. If the header only uses a pointer to that type, replace the include with a forward declaration and include the real header in the cpp file.
Do I need to delete Intermediate to fix this error?
No. Unreal Header Tool runs on every build, so moving the include is enough. Delete Intermediate and Binaries and regenerate project files only when generated files are stale, for example after renaming or deleting headers or switching engine versions.
Can a forward declaration go after the .generated.h include?
Yes. The rule applies to include directives only. Forward declarations such as class USphereComponent are ordinary C++ declarations and normally sit just below the include block, above the class.
What is the .generated.h file named after?
The header file, not the class. A header called Enemy.h must include Enemy.generated.h even if the class inside is AEnemyCharacter. After renaming a header file, update the generated include to match.
The generated include is named after the file and goes last, every time. If a tool adds an include for you, check which side of that line it landed on before you build.