Must new c++ Code be added from editor?

Hello everyone,

Got a quick question, every time I try to add new .h and .cpp directly from VC2013, the project refuses to compile. This does not happen when I add file one by one through unreal editor though (same exact codes). So i’m wondering if editor is the only way to add files to your project, or am I doing something wrong?


Same here.I think its about “ClassName.generated.h” which adding from VS isnt generating it.

Please try to search before you ask, it’s just 5 threads next to yours…

You need to pay attention to where VS is creating the new source file, the default location for new files you create in VS is the location of the VS project file. The VS project files are generated in the Intermediate directory, but all source files must be placed in sub-directory within the Source directory. So when creating a new source file in VS you need to change the destination directory.

I tried right-click and generated vs file like the other post suggested, but it didn’t work. (I put them in source folder too.)
When files are created outside of editor, I always get compile error:

“The first include statement in source file ‘[somefile].cpp’ is trying to include the file ‘[somefile].h’ as the precompiled header for module ‘[project]’, but that file could not be located in any of the module’s include search paths.”

I have used VS c++ for ages, but I never have problem with the include files… Usually, I can just right click and add new files and they’re linked to the project automatically. Is unreal project set up in some wield way that prevent this from happening? What exactly does right-click “generated vs file” suppose to do for us?

Thank you for replies folks,

It’s expecting the first include in the file to be for the precompiled header, this is how things are setup by default. UnrealEd tends to name the precompiled header MyProjectName.h (where MyProjectName is the name of your project), and assuming you’ve created your project via UnrealEd the precompiled header should already exist.

When you build a UE4 project VS doesn’t invoke msbuild/compiler/linker directly, it invokes the Unreal Build Tool (UBT). UBT will run through your source (on disk) and figure out all the compiler/linker options and include search paths and such based on the Build.cs and Target.cs files, then it will use the VC toolchain to generate the binaries. The VS project files generated via the right-click menu provide a convenient way to edit and debug your code, but as far as I understand they do not have any influence on the build process.

MyProjectName.h does exist, but I couldn’t locate its precompiled file though. All .cpp files that was created from VSC++ always give out [that file could not be located in any of the module’s include search paths] error when we have them declare MyProjectName.h. Files that were generated from Editor are fine though. However, if we remove and reimport them with VSC++, we get the same errors.

Is there anyway to fix this?

Delete “DependencyCache.bin” and build project.
ex) Unreal Projects\ProjectM\Intermediate\Build\ProjectMEditor\DependencyCache.bin

Thank you snowy5719!

Saved my butt with “all source files in module must include the same precompiled header first”

Thanks! :smiley:

No u dont have to use Editor.

I am adding C++ code to my project by following steps:

  1. Create link to GenerateProjectFiles.bat, and change command line arguments of that link for generating files for my particular project: …GenerateProjectFiles.bat -Game “D:\Unreal Projects\MyProject\MyProject.uproject” -Engine
  2. Adding new folder/.cpp/.h files to my project, using any file manager.
  3. Launching (1) link.
  4. My new project files regenerated, if project is currently opened, then VisualStudio will ask me Reopen files, i press Reopen. Done.

You can just put your C++ source codes into Source folder, then it will scan by Unreal Build Tool and get Compiled. You just need to Regenegerate with .uproject file, then you got the updated Visual Studio Project files.