Wrapping reusable C++ in a separate project

Setup

I have some code I reuse across multiple projects. It’s code I use for a flag system, event system, etc. It’s a good number of classes and it’s growing slowly.

Problem

When I edit or update the code in one project it needs to be migrated to all others using the code. This means the code has to update the MYPROJECT_API tags and MyProject.h headers all over. Changing these and copying the code back and forth is very messy.

Question

Is it possible to put all these classes into a separate Project and include it in all the solutions that are using it? So it can be easily reference it in via #include. Similar to a namespaced public project in C#.

I’ve heard about editing the build.cs etc. but how exactly would I do this? Does anyone have any experience on this?

Example

For Example: I would like to use the public classes in Wingless (A UE4 Project) in the current solution for MerForge (Also UE4 Project).

46555-2015-06-15_23-23-15.png

You can write your reusable code in plugins/modules or even just plain class/folder structure. Then you add proper include paths in your Build.cs files.

I would like to use the class/folder structure, since the code isn’t actually a plugin. Do you have any advice or examples on how to link it in the build.cs. I’m having trouble finding a clear example.

Try something like:

string FBXSDKIncludePath = "C:/Program Files/Autodesk/FBX/FBX SDK/2015.1/include";
PublicIncludePaths.AddRange(new string[] { FBXSDKIncludePath });

Then you can include .h files under that directory in your project.

Tested and seems to be working thank you!

I am also looking for an answer to exactly what you ask for, did not really understand the answer below. How do you solve the MYPROJECT_API tags that has to be changed between different projects?

I ended up using a module to store all my reusable code: Gameplay Modules | Unreal Engine Documentation

Creating a Runtime module like RDS-Wojtek suggested was the answer.

Sorry for late submission of answer. Wanted to come back and mark this as answered for others to find.