## How to Add C++ Class to Unreal Engine 4 Project

If you manually add classes to your project you will have full control over when the code will be compiled. What I usually do is this:

1. Open the file browser and navigate to the project’s directory.
2. Go to the correct source directory and create there two text files (the .h and the .cpp). Usually the “correct directory” is: [project directory]/Source/[project name]
3. Repeat step 2 for each class (or struct) that you want to add into the project
4. Inside Visual Studio, right click in the solution explorer’s correct “folder”, Add -> Existing Item... and then select the two (or more files) created in step 2.

Why not use the Add -> New Item... or even Visual Studio’s Class Wizard? They do work and I only avoid those because of the fact that Visual Studio always want to create the new files in the wrong directory (inside the Intermediate subdirectory). What this means is that for each .h/.cpp pair to be added you will have to remember to point Visual Studio to the correct location. While the project will build, there are a few problems with this:

• Sometimes during the project development you will need to perform some cleanup in order to solve some problem in your project. This cleanup usually involve deleting the Intermediate directory.
• It breaks file organization.
• When performing backups you will probably not include the intermediate subdirectory.

I have presented here 3 slightly different ways of adding new C++ classes to your Unreal Engine project. All 3 have the same problem and that is the fact that you will have to add the boilerplate code to your new files. Visual Studio’s Class Wizard at least add some code (the class declaration and definition) to the generated files. Don’t worry too much if you don’t know what this boilerplate code is, because with time you will learn where to look at as reference code and then copy/paste to your own files.

With all that said, I encourage you to experiment with the available approaches, see which one you like and then stick to it.