UE5 Expected an include at the top of the header generated.h

UE5 expected an include at the top error

How to fix Unreal Engine Error: Expected an include at the top of the header: ‘#include “XXX.generated.h”. This is an error thrown by Unreal Build Tool when the developer has either not written the ‘include..’ line or there are spelling mistakes. Follow these steps to solve it.

Summarised Solution

  1.  Ensure the ‘#include… generated.h’ line is the last of all includes.
    The line “#include xxxx.generated.h” has to be in your header file and the last of all includes.

     

  2. Ensure the file name of the header and the suggested generated.h match. 

    In the line “#include xxxx.generated.h” ; xxxx has to match your header file name.eg Actor.h needs Actor.generated.h
    Resharper sometimes changes the file name when refactoring.

  3. Next Delete Intermidiate folder and regenerate project files.
    Delete the Binaries and Intermediate Folders and Regenerate project files from the uproject.