Ok, so It looks like I managed to do it, thanks to [USER=“434”]BrUnO XaVIeR[/USER] hint.
To wrap it up for ppl just starting like me :), here’s a mini tutorial if you’re creating a runtime (game) project plugin that needs Editor functionalities when in Editor:
1. Add a Module of type Editor to your plugin: [Project_root]/Plugins/<yourPluginName>/Source/[Add YourPluginEditor folder] and replicate the folder structure (Private/Public… etc.)
2. Add the Editor Module to the <YourPluginName>.uplugin descriptor:
"Modules": {
"Name": "<YourRuntimePluginName>", // <-- Your existing Runtime Plugin module
"Type": "Runtime",
"LoadingPhase": "PreLoadingScreen" // <-- This is up to you...
},
{
"Name": "<YourEditorModuleName>", // <--- This is your new Editor Module!
"Type": "Editor", // <-- This could also be "UncookedOnly"... try it out
"LoadingPhase": "PreDefault" // <-- This is up to you...
}
]
3. Your Runtime module needs to statically link the Editor Module when in Editor. This happens only when UBT builds the Editor target: in .Build.cs, somewhere inside the Module class “public YoutPlugin(ReadOnlyTargetRules Target) : base(Target)”:
if (Target.Type == TargetType.Editor) // Is UBT building for Editor ?
{
PrivateDependencyModuleNames.Add("<YourEditorModuleName>");
}
4. In your Runtime Module source code you need to safeguard from Editor functionalities by using the pre “WITH_EDITOR”. This clearly goes for actual implementation and include directives:
#include <StuffForRuntime>
#if WITH_EDITOR
#include <YourEditorModuleHeader>
#endif
...
...
[Runtime code]
#if WITH_EDITOR
<Use YourEditorModule Classes>
#endif
This also won’t cause issues when packaging your entire Plugin, from the Editor (Plugin -> Package).
How to expose the class in your new Editor module to the Runtime code is entirely another story. To learn a bit more I went the hard route of implementing a UINTERFACE, but I guess it can be done in many different, simpler ways.