How to include private header files of other Modules into my Module?

Hi,

I try to create a Plugin with an editor module for a component Visualizer.
I have trouble in understanding and setting up the MyToolEditor.Build.cs
I want to extent an already existing Component Visualizer but this Visualizer is declared in the private Folder of the ComponentVisualizers Module.

My Question is, how could I access this?
How can I include private header files of other Modules?

I tried something like this, but with no luck

PrivateIncludePaths.AddRange(
	new string[] {
		"MyToolEditor/Private", 
		"Editor/ComponentVisualizers/Private"
	}
);
1 Like

I’ve tried to do that in many ways without success, but finally nailed it!

This works for engine modules:

using System.IO; // Note this import, it's needed below

namespace UnrealBuildTool.Rules
{
    public class Foo : ModuleRules
    {
        public Foo(TargetInfo Target)
        {
            // ...
            // Get the engine path. Ends with "Engine/"
            string engine_path = Path.GetFullPath(BuildConfiguration.RelativeEnginePath);
            // Now get the base of UE4's modules dir (could also be Developer, Editor, ThirdParty)
            string srcrt_path = engine_path + "Source/Runtime/";
    
            // now you can include the module's private paths!
            // as an example, you can expose UE4's abstraction of D3D11, located in Source/Runtime/Windows/D3D11RHI
            PublicIncludePaths.Add(srcrt_path + "Windows/D3D11RHI/Private");
            PublicIncludePaths.Add(srcrt_path + "Windows/D3D11RHI/Private/Windows");
        }
    }
}
5 Likes

Thanks for posting your solution! Helped me solve the same issue today!

You rock! Thanks!

This was helpful! Thanks!

Where I have to write this?

Thanks! :slight_smile:

since 4.18:

string engine_path = Path.GetFullPath(Target.RelativeEnginePath);

7 Likes

Your *.Build.cs file for the project.

I came across this post and figured I would add an example I see used in other Engine code. In my case I wanted to access private headers from Slate in my own Editor tool code. I added the following in by .Build.cs file:

PrivateIncludePaths.AddRange(new string[] {
    System.IO.Path.Combine(GetModuleDirectory("Slate"), "Private"),
});

I can then include the header I’m after (Engine/Source/Runtime/Slate/Private/Framework/Docking/SDockingTabStack.h) as

#include "Framework/Docking/SDockingTabStack.h"

Cheers.

2 Likes