GENERATED_BODY() Macro Error with Intellisense

Hey has anyone ever had an issue with Visual Studio Header files where the Generated_Body() Macro throws an error if you add any extra include statements or spaces to the top of the header file? I was working on a project prior to this one and had no issues with intellisense, but now every time I create a new c++ class I have this error when adding additional include statements.

Usually visual studio does that type of Black Magic non-sense thing like:

hEy I tHinK yOu HaVe An ErRoR hErE!!!

Usually you can ignore it, the project will still compile, the thing is, Visual Studio Intellisense w/ Unreal by default is not the optimal way to go, I would suggest to take a look into Visual Assist.

But for future reference if this happens and your project is not compiling:

The error may be related to a conflict between the include statements in your code and those in the generated files.

Since the generated files are created by Unreal Engine’s reflection system, and any modifications made to them may cause issues.

To avoid this type of error, it’s recommended to not modify the generated files directly. Instead, you can add any additional include statements to your own source files or header files.

you can also try the following steps to resolve the issue:

  1. Clean your project and rebuild it. In Visual Studio, go to “Build” > “Clean Solution” and then “Build” > “Rebuild Solution”.

  2. Check your project’s include paths to ensure that the necessary header files are being found. To do this, right-click on your project in the Solution Explorer and select “Properties”. Then, navigate to “C/C++” > “General” > “Additional Include Directories” and make sure that the necessary paths are listed there.

  3. Make sure that you are using the correct include statement syntax. In C++, you should use angle brackets for system includes (e.g. include < iostream >) and double quotes for project-specific includes (e.g. include “MyHeader.h”).

1 Like

Thanks for the help. I will try a couple different things to see what solves the problem

Happens for me as well. To my knowledge this has to happen and there is no way around it. Reason being that the generated.h file and the code generated from expanding the GENERATED_BODY both include line numbers. And when you add anything that changes the line number in the GENERATED_BODY they won’t match what has been generated in the generated.h. So usually what fixes it for me is to build since that will regenerate generated.h so that line numbers should match again.

2 Likes

Easy sure fix: Build->Build Full program database. This will reset Generated Body default line to Visual studio. so whenever you make changes to generated body line change then you will repeat this step and it is better to do this in advance and leave about 10-12 lines for work everytime you create new class.