UHT wrongly complains about precompiled header include

I have a source file that I use in multiple projects, and it needs its first #include to be for its precompiled header. My problem is, the precompiled header is different for each of my projects. My solution to this is to add preprocessor directives to change the first #include depending on which project is compiling the file.

#ifdef FIRST_PROJECT_API
  #include "First_Project.h"
#else
  #include "Second_Project.h"
#endif

The way that the preprocessor directives are highlighted in Visual Studio shows me that they should be working as expected. However when I compile my VS solution for Project 2 it complains that my first #include is for the file “First_Project.h” which it can’t find.

This is a bug in Unreal’s build process, as it doesn’t consider conditional preprocessor directives when trying to find the first #include in a file.

It’s not compiler but UHT error most likely, it is known that it does ignores conditionals, i seen raport of that in the past

I can think you could work around it by creating header file of same name in both project and make proper include there.

Btw, if you start to use same code over same multiple projects, it means it’s time to move it to a plugin where you can easily reuse that code with just one click of a button, that what plugins was made for

I don’t want to have to make a plugin that encompasses a few files that I would have to recompile separately every 10 minutes or so when I want to test new features. If this feature is not in the UHT then it really should be. The error message I’m getting says:

‘C:\Users\WS013\Downloads\UNREAL DEMO\UNREAL DEMO\MyProject\Source\First_Project\AxonPawn.cpp’ is trying to include the file ‘Second_Project.h’ as the precompiled header, but that file could not be located in any of the module’s include search paths.

That statement is flat out wrong, I’m not trying to include that file. If nothing else the error message should be updated to say “the first instance of ‘#include’ we found in our plaintext search” rather than “is trying to include the file ‘Second_Project.h’ as the precompiled header” because the file IS NOT trying to do that.

Looks like this has already been submitted as a bug report/feature request UE-20145