How do I force include a game header file?

I would like to force include a header file in all of my games .cpp files. Something like this:

CompileEnvironment.ForceIncludeFiles.Add(“MyForceIncludeFileName”);

I get a ‘CompileEnvironment’ does not exist in the current context error.
What is the best way to do this?

Apologies if this is in the wrong place, I did not see a UBT or C# section.

I’m not aware of a way to do this in UBT. In fact, I’m not aware of a way to do it in any build chain.

Imagine for a second that one day, deep into your project, you suddenly want to make a single cpp file that doesn’t include that header. Or say you suddenly realize you need your header to come after or before another header or pragma or something else in one of your cpps.

I’m guessing these are some of the reasons includes are typically a manual thing, just like including the header that matches your cpp, or things like #pragma once guards in your headers.

That said, you could certainly write, say, a Python script that would iterate through each of your cpp files and look for the #include at the top of the file (and either warn you or go ahead and insert it if doesn’t exist), and call that as a “PostBuildStep” in your uproject or uplugin file.