Include file not found when in another folder

I have a C++ project. My game’s source file structure is as followed:




Lets say i have two classes with their .h and .cpp at:






#include "NewCharacter.h" // This does NOT find the include file
#include "Characters/NewCharacter.h" // This does find the include file.

Is it normal to have to include the full path? I have always been used to a build process that includes a root that is searched recursively for include files. I was assuming that the project source root would be that but apparently not. Thoughts?

Compiler is searching them in all include paths that is configured to search (usally done in compiler arguments. In UBT you can add include paths in build script in PublicIncludePaths and PrivateIncludePaths array

Why wouldn’t the root of the project’s source not be automatically added? Anyone wanting to use folders and include a .h in another folder would have this issue.

I see a lot of people using PrivateIncludePaths for third party libraries but not necessarily their own game code.

It almost feels like I am missing something obvious here.

“root of the project’s source” is added automaticly and you include examples shows that, but does not search recursively (thats what i meant). Compiler (because we talking here about compiler feature not UE4) only search for matching paths in configured include paths. If you look up in engine source code which work same way as game code (game module is just another engine module, it is in seperte forder so you can have multiple project sepretly, but it works the same and practicly you extending engine code from it) it also uses full parths, most common example “GameFramework/Actor.h” which is included in all AActor based classes. It is UE4 convention, but if you like you can alter include path list in build script.

Is there a way to have ti search recursively or will I need to add every folder? Also when adding to PrivateIncludePaths how do I get the project root?

Using the [project_name].build.cs file, you should be able to iterate through folders using DirectoryInfo.

yea its C#. the “current directory” in build script is “Source” directory, it otherword you need to include module directoiry it to the path

Thanks all got it working. Directory.GetCurrentDirectory actually returns a path in the engine code not the project root. I found online someone that found the ModuleDirectory variable. That leads us to the exact spot we want …/Source/ProjectName/. I then get all the directories recursively and add them to the PrivateIncludePaths.

    private void IncludeSubdirectoriesInIncludePaths()

    private void AddDirectoriesRecursive(string DirectoryPathToSearch)
        foreach (string DirectoryPath in Directory.GetDirectories(DirectoryPathToSearch))