How do you Include/Exclude files from Build?

I use the ‘Include/Exclude’ commands in Visual Studio a lot for educational purposes, but these commands don’t work in UE4 projects, the files just mysteriously vanish and using ‘Show All Files’ does not reveal them.

How do you Include and Exclude files from a build in a UE4 project in Visual Studio? Or do you have to just drag them out of the folder in File Explorer?

Here is someone else who had same problem:

Bumping this till somebody answers

3 days ago… are there no answers on answerhub?

I agree, answerhub doesn’t normally provide any answers at all… oh well. What is the use case - what are you trying to do? You can exclude content from within UE4 from the cooked version of your game (project settings → packaging → Directories to never cook). If you want to exclude a third party plugin, just unselect it in the plugins menu.

If you are actually talking about compiling a version of the engine without certain files then you will need to use preprocessor macros, and that’s the way it works. Once the compiler finds something in the include list it compiles it, so you can’t do a broad exclude folder thing.

As above. I don’t think there is really an answer outside of those suggested in the link you provided. Modularise your code or use preprocessor macros.

If neither of them are an option then you might be able to modify the engine so you can run a custom version of Generate VS Project files which selectivly includes / excludes, or perhaps modify the build process itself but I imagineyou wouldn’t find too much information on what that involves other than reading through the source.

Ok, preprocessor macros it is then. Sounds like some custom tooling is in order…

would love to hear of other ways, do go on.

I am really just adventuring around in the engine.

If you could provide more details about what you’re trying to do we could try other suggestions. If you have a load of 3rd party CPP files there are other ways to get them compiled into the engine (or not) without adding them to a module source folder where UBT will always build them.


If you have some nasty 3rd party library that would cause all sort of mayhem when compiled directly with other UE4 code (for example, something that needs CMAKE to build), you can try compiling it as a 3rd party library. You can then add a build.cs file to it and add it as a module to your own modules for easy consumption.

A good place to look is the Engine\Source\ThirdParty folder in your UE4 installation. The ICU is a good example: it’s massive and it includes source code for the library itself.

The Runtime Mesh Loader plugin is also nice to study: [Plugin] Runtime Mesh Loader - Engine Source & GitHub - Unreal Engine Forums

It’s a plugin built on top of the open source Assimp 3D model loader/writer library and there’s full source too.

But if you really want to add a bunch of cpp files directly and be able to quickly toggle them on/off, you can place them somewhere outside the reaches of UBT (a folder one level outside the module’s source folder), and #include all your CPP files in a single .cpp inside your source folder. This way you can use a single #define to enable/disable them all.

I like it, I will investigate this. Thanks