I write in my cpp file
#include “Components/ActorComponent.h”
But really, the ActorComponent.h file placed at /UE4/Source/Runtime/Engine/Classes/Components/ActorComponent.h
I understand that “Engine” module placed in the folder /UE4/Source/Runtime/Engine, so ok, if i use “Engine” module, then i can use relative path. But it should be “Classes/Components/ActorComponent.h” (not just a “Components/ActorComponent.h”)
How does VS understand that Components/ActorComponent.h should be searched inside of “Classes” subdirectory? Where is it specified?
The same question with includes of modules. For example FoliageModule.cpp exists in directory Foliage/Private. FoliageModule.h exists in directory Foliage/Public
But .cpp uses header without any directory structure. As if both files placed in the same directory:
#include “FoliageModule.h”
2 Likes
The Build.cs file of that Module declared that “Classes” directory or the path to that “Public” folder as a public include path.
So anything inside those folders will be added to the header search when the build tool is compiling the project.
That’s why “Components/ActorComponent.h” is a valid path. “…/Classes/” is appended to it by the build tool because it’s a public key path (look into Build.cs files for examples).
1 Like
I thought so too, but i`ve checked file “engine.build.cs” (ctrl+f => Classes), but there is no mention of “classes” inside.
1 Like
The UnrealBuildTool does all that and simply adds the directories to the Project Include Paths.
From UEBuildModuleCPP.cs:
private void AddDefaultIncludePaths()
{
// Add the module's parent directory to the public include paths, so other modules may include headers from it explicitly.
PublicIncludePaths.Add(ModuleDirectory.ParentDirectory);
// Add the base directory to the legacy include paths.
LegacyPublicIncludePaths.Add(ModuleDirectory);
// Add the 'classes' directory, if it exists
DirectoryReference ClassesDirectory = DirectoryReference.Combine(ModuleDirectory, "Classes");
if (DirectoryLookupCache.DirectoryExists(ClassesDirectory))
{
PublicIncludePaths.Add(ClassesDirectory);
}
// Add all the public directories
DirectoryReference PublicDirectory = DirectoryReference.Combine(ModuleDirectory, "Public");
if (DirectoryLookupCache.DirectoryExists(PublicDirectory))
{
PublicIncludePaths.Add(PublicDirectory);
ReadOnlyHashSet<string> ExcludeNames = UEBuildPlatform.GetBuildPlatform(Rules.Target.Platform).GetExcludedFolderNames();
EnumerateLegacyIncludePaths(DirectoryItem.GetItemByDirectoryReference(PublicDirectory), ExcludeNames, LegacyPublicIncludePaths);
}
// Add the base private directory for this module
DirectoryReference PrivateDirectory = DirectoryReference.Combine(ModuleDirectory, "Private");
if(DirectoryLookupCache.DirectoryExists(PrivateDirectory))
{
PrivateIncludePaths.Add(PrivateDirectory);
}
}
2 Likes
For QT Creator, the information is stored in file UE4Headers.pri (of course generated by UBT) with the format
HEADERS += \
"$$unrealRootPath/Engine/Source/Programs/BlankProgram/Private/BlankProgram.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/BuildPatchTool.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/Interfaces/ToolMode.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/ToolModes/AutomationMode.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/ToolModes/ChunkDeltaOptimiseMode.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/ToolModes/CompactifyMode.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/ToolModes/DiffManifestMode.h" \
"$$unrealRootPath/Engine/Source/Programs/BuildPatchTool/Public/ToolModes/EnumerationMode.h" \
"$$unrealRootPath/Engine/Source/Programs/CrashReportClient/Private/Linux/LinuxErrorReport.h" \
...
which tells it where to look for the header files. I have no clue about the “relative path” scheme however.
1 Like
Built-in engine modules are already set by default.
When creating custom modules you usually have to declare them to be set in the list.
1 Like