Adding a #include always breaks everything. Fix?

Every time I have to “IWYU” and add a #include into a header file, the corresponding cpp file breaks intelisense and can only compile in UE.

The only work around I’ve figured out it to quit and relaunch Visual Studio. Is there something I’m doing wrong, or a better solution?

I remember him saying that it took a little while for the #include to work once you put it in and the intelisense to catch up and as it seem to be working in the long run if your quiting and relaunching to solve it it might just need more time to bring the files in?

Good luck :wink:

MrSofaNinja is correct, Intellisense will show errors after adding an #include and this is especially evident in later versions of UE4 due to the introduction of IWYU (Include what you use).

You can force intellisense to update by going to the Project dropdown in Visual Studio and choosing Rescan Project. This will take a while though and may not be worth it as the Intellisense issue will NOT cause the project to stop compiling.

The lecture in video urc_s03_resetting_your_unreal_project is the fix for this problem.

It has to do with the .generated.h files containing references to the physical line numbers of the UCLASS and GENERATED_BODY() macros. If the line number for these macros change, i.e. adding any line above them, it breaks the generated.h files. Performing the steps in the reset your project lecture fixes it reliably.

What I like to do is go into header file for any new class I create, create 3 or 4 empty lines above the first #include directive and then reset the project. This will create an area where you can add #include lines without breaking the project every time.

1 Like

Woah, the line number matters? That seems crazy.

Bit late to this, but this isn’t 100% true (and I may save you some time here). The line number AFTER the line including #include "Class.generated.h" matters. So you can add as many includes as you want before this line, as long as the space between #include "Class.generated.h",UCLASS and GENERATED_BODY() remain consistent. So no need to keep resetting your classes!

Privacy & Terms