How to Include files from another module

We made another module. but doens’t seems to allow me to include how do we include files from another module

Have you added the module you want to include files from into the PublicDependencyModuleNames or PrivateDependencyModuleNames list in the .Build.cs file of the module you want to add the includes to?

Also, what is the layout of the module you’re including files from? Only files in a Public folder will be accessible in another module, and everything else is considered Private (although I think that might have been changed for 4.3 so that files in the root of a module folder are also considered Public).

Actually I’m intending to add gameplay module to the shootergame project so it’s portable between versions.

I’m intending to extend from AShooterGameMode…

these are my build files in my new module:
PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “ShooterGame” });

PrivateDependencyModuleNames.AddRange(new string[] { “InputCore”, “ShooterGame” });

Since you did mention that only public folder is accessible. Which means I don’t think it’s possible to include anything from ShooterGame module then since only ShooterGame.h is in public?

You should be able to include ShooterGameMode.h as it’s in the Classes folder (sorry, I forgot about that one since it’s semi-deprecated and not used for new stuff; Classes has the same accessibility as Public).

Your .Build.cs file looks correct to me, what is the path you’re using in your include?

Also, it seems that AShooterGameMode isn’t API exported, so even if you can include it, you’ll let a linker error trying to use it in another module (it needs a SHOOTERGAME_API - this is why we moved away from the Classes folder, since you can’t easily tell what you should be able to use in another module).

Something super weird just happen. I did it this manner.

#pragma once
 
#include "ShooterGame.h"
#include "PCGameMode.generated.h"
 
UCLASS()
class APCGameMode : public AGameMode
{
        GENERATED_UCLASS_BODY()
 
};

and suddenly I’m getting errors on totally unrelated class .

1>------ Build started: Project: ShooterGame, Configuration: DebugGame_Editor x64 ------
1> Parsing headers for ShooterGameEditor
1> Code generation finished for ShooterGameEditor and took 8.101
1> Performing 5 actions (max 4 parallel jobs)
1> PCH.ProjectCombine.ProjectCombine.h.cpp
1>c:\users\alfred\documents\unreal projects\shooter game 4.2\intermediate\build\win64\inc\shootergame…/…/…/…/…/Source/ShooterGame/Classes/Online/ShooterGameSession.h(3): fatal error C1083: Cannot open include file: ‘ShooterLeaderboards.h’: No such file or directory

Let me search up on the API exported thing a while.

It seems that ShooterGameSession.h (which is in Classes) is including ShooterLeaderboards.h (which is in Private). ShooterGame.h includes ShooterGameClasses.h, which is in turn trying to include a Private file… that is doomed to failure, and I’m not exactly sure how ShooterGame is getting away with it (although I suspect it’s because all the files are in the same module, and because ShooterGame.h has never been included outside of the Private folder of ShooterGame before).

Sorry to bother you again. Do you have any documentation on what it means to be API Exported? and how do we go about doing it?

If it’s going to be too much work to make shootergame API Exported then we’ll perhaps move on to other approach.

We have some information on Gameplay Modules: Gameplay Modules in Unreal Engine | Unreal Engine 5.1 Documentation

I’ve also answered another question about it before: What does COREUOBJECT_API & ENGINE_API macro? - C++ - Epic Developer Community Forums

Don’t mean to dig up a dead topic but has there been any solution to this issue? I’m having the same trouble, can’t access ShooterGame module from another module because of privacy/dependency issues. It seems like you guys are aware of the issue judging from this thread but I can’t find a solution anywhere and it hasn’t been patched as of 4.6

edit: Managed to get it working by simply moving the ShooterLeaderboards.h into the Public folder. That solved that issue but opened up access to a few others lol. Either way, nevermind.