Search code examples
c++unreal-engine4unreal-engine5unreal

Unreal Engine 5 module: how to include named module from Public folder?


I've created a module in my UE5 game, called MinimapSystem and structured it like this (this is inside my game's Source folder):

MinimapSystem
    ├───MinimapSystem.Build.cs
    ├───Private
    │   └───MinimapSubsystem.cpp
    └───Public
        └───MinimapSubsystem.h

Here's the contents of my MinimapSystem.Build.cs file:

using UnrealBuildTool;


public class MinimapSystem : ModuleRules
{
    public MinimapSystem(ReadOnlyTargetRules Target) : base(Target)
    {
        PublicDependencyModuleNames.AddRange(new string[]
        {
            "Core",
            "CoreUObject",
            "Engine",
            "UMG"
        });
    }
}

This imitates what I see in the core UE5 module structure, and when I include one of those modules, I don't need to specify the Public/ part of the path, i.e.

#include "GeometryCollection/GeometryCollectionActor.h"

So, in my game, I try the same thing with my module:

#include "MinimapSystem/MinimapSubsystem.h"

But this throws a fatal error when I try to compile:

fatal error C1083: Cannot open include file: 'MinimapSystem/MinimapSubsystem.h': No such file or directory

The only way to compile my game is if I specify the Public/ folder like this:

#include "MinimapSystem/Public/MinimapSubsystem.h"

I have added my module to MyGame.Build.cs like this:

        PublicDependencyModuleNames.AddRange(new string[]
        {
            "Core",
            "MinimapSystem",
        });

How do I include my module by its name from the Public folder?


Solution

  • The solution is to structure the module like this:

    MinimapSystem
        ├───MinimapSystem.Build.cs
        ├───Private
        │   └───MinimapSubsystem
        │       └───MinimapSubsystem.cpp
        └───Public
            └───MinimapSubsystem
                └───MinimapSubsystem.h
    

    This emulates the actual structure of i.e. the GeometryCollection module. Now, I can include my module like:

    #include "MinimapSystem/MinimapSubsystem.h"