You’re going to want to make a new module to build your editor specific code, so that it’s separate from your game code. Unfortunately we don’t seem to have an example/sample which does this, however I’ll try and walk you through it as best I can.
If you go to the Source folder for your project, you’ll notice you have two .Target.cs files; in my case I’m going to pretend your project is called “MyCodeProject” (replace as appropriate), so you’d see:
- MyCodeProject.Target.cs
- MyCodeProjectEditor.Target.cs
If you open up these files, you’ll notice that they both output a single module from SetupBinaries, what we’re going to do is add an extra module called “MyCodeProjectEditor” to contain your editor code.
Open MyCodeProject.Target.cs and in SetupBinaries add the following:
if (UEBuildConfiguration.bBuildEditor)
{
OutExtraModuleNames.Add("MyCodeProjectEditor");
}
Open MyCodeProjectEditor.Target.cs and in SetupBinaries add the following:
OutExtraModuleNames.Add("MyCodeProjectEditor");
Now, inside your Source folder, create a new folder called “MyCodeProjectEditor”, and copy the following files from the “MyCodeProject” folder, into “MyCodeProjectEditor” folder:
- MyCodeProject.Build.cs
- MyCodeProject.h
- MyCodeProject.cpp
Rename these files in the “MyCodeProjectEditor” folder so you see:
- MyCodeProjectEditor.Build.cs
- MyCodeProjectEditor.h
- MyCodeProjectEditor.cpp
Open MyCodeProjectEditor.Build.cs and rename the class from “MyCodeProject” to “MyCodeProjectEditor”.
Open MyCodeProjectEditor.cpp, and fix the include name, and then change the macro which implements the module to be:
IMPLEMENT_GAME_MODULE( FDefaultGameModuleImpl, MyCodeProjectEditor );
Finally you need to update your .uproject file so that it knows about your new module, so open that up in some form of competent text editor (eg, Notepad++), and adjust the “Modules” section so that it contains your new editor module; when you’re finished, it would look something like this:
"Modules": [
{
"Name": "MyCodeProject",
"Type": "Runtime",
"LoadingPhase": "Default"
},
{
"Name": "MyCodeProjectEditor",
"Type": "Editor",
"LoadingPhase": "Default"
}
],
If you re-generate your projects and build, you should hopefully now have a separate editor module. You’ll be able to use this module to contain your editor specific code (move the editor dependencies into the MyCodeProjectEditor.Build.cs file, and move the editor specific code into that module folder).
You’ll probably also want to add “MyCodeProject” to the PublicDependencyModuleNames in your MyCodeProjectEditor.Build.cs file, as this will allow your editor module access to your game code.