https://docs.unrealengine.com/latest/INT/Programming/Modules/Gameplay/index.html
I tried looking at this, but I have had no luck following it. How do you make Visual Studio detect [GameName]\Source[ModuleName]\Public\ and [GameName]\Source[ModuleName]\Private\ when the editor puts code in [GameName]\Source[GameName]\ ?
That article seems to be lacking quite some information.
I was able to get a module to compile for UnrealTournament. I’ll use the same macros [GameName] and [ModuleName] to keep it as generic as possible:
-
Add the following line in
Source\[GameName].Target.csandSource\[GameName]Editor.Target.cs(in theSetupBinariesmethod):OutExtraModuleNames.Add("[ModuleName]"); -
In the
Source, create a directory called[ModuleName]
(I believe that in the article you mentioned, there is a typo that lacks a backslash!) -
In
Source\[ModuleName], create a file called[ModuleName].Build.cswith the following content (edit the dependencies as required):using UnrealBuildTool; public class UTRPG : ModuleRules { public UTRPG(TargetInfo Target) { PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine" }); } } -
Create the directories
PrivateandClassesinSource\[ModuleName]. I have no idea when to usePublic, in the UT source code, it doesn’t even exist. -
In
Private, create a file called[ModuleName].cppwith the following content:#include "[ModuleName].h" #include "[ModuleName].generated.inl" IMPLEMENT_PRIMARY_GAME_MODULE(FDefaultGameModuleImpl, [ModuleName], "My Module");Also in
Private, create[ModuleName].hwith:#ifndef __MODULE_NAME_H__ #define __MODULE_NAME_H__ #include "Engine.h" /* ... add an include for each of your classes here and include this header in every source (cpp) file ... */ #endifNote: that
.generated.inlfile that’s being included in the source only seems to be generated if you have any classes at all. -
Put your class header files (h) into the
Classesdirectory and the source files (cpp) into thePrivatedirectory. When you build the game project, your module should now be built as well.
I hope this helps, but I cannot really explain all of those steps. It was a matter of trial and error.
I’d be really grateful if somebody who has the authority edited the article you linked to, because it lacks a bunch of information that’s apparently required.
For instance, while I can compile my module that way, I have not found a way to make the game load the module. Editing the INIs as described in that article does not seem to do anything (or not enough). I have posted a question regarding that here: How can I get a Gameplay Module to load? - Programming & Scripting - Epic Developer Community Forums