Is it possible to make a plugin that can be used in Editor and also get packaged as runtime?

Hey,

so me and my project group are working on a plugin for an university project, which is operable through the Editor’s toolbar.

All of that works so far, but we have some C++ Content in the plugin that needs to be used at runtime.
The problem is, that an editor plugin does not seem to be able to be packaged.
In the packaged project, there is no plugin folder and the C+±Classes seem to be gone, while the Blueprints located inside the plugin’s content folder are functioning.
Changing the type in the .uplugin to Runtime produces an error, since UnrealEd can not be instantiated for non-editor targets.

This is the part that produces errors while packaging in a test project:

UATHelper: Packaging (Windows (64-bit)): ERROR: Unable to instantiate module ‘UnrealEd’: Unable to instantiate UnrealEd module for non-editor targets.
UATHelper: Packaging (Windows (64-bit)): (referenced via Target → VIR_ENVIRONMENT.Build.cs)
PackagingResults: Error: Unable to instantiate module ‘UnrealEd’: Unable to instantiate UnrealEd module for non-editor targets.
UATHelper: Packaging (Windows (64-bit)): Took 3,8490541s to run UnrealBuildTool.exe, ExitCode=6
UATHelper: Packaging (Windows (64-bit)): UnrealBuildTool failed. See log for more details. (C:\Users\spata\AppData\Roaming\Unreal Engine\AutomationTool\Logs\F+EpicGames+UE_4.26\UBT-ue4_vir_env-Win64-Development.txt)
UATHelper: Packaging (Windows (64-bit)): AutomationTool exiting with ExitCode=6 (6)
UATHelper: Packaging (Windows (64-bit)): BUILD FAILED
PackagingResults: Error: Unknown Error

Is there any way to make it work for both the editor and runtime?
Or do we have to split the plugin into two separate ones, one with the editor functionality and another one with the other content?

Best regards

If you have a dependency on Editor-Only modules, you will need to either split out your plugin into Runtime and Editor components, or edit the .uplugin/.build.cs to exclude the Editor stuff when not building in Editor configuration

The Editor GUI does not exist in a packaged build.

Plugins can have multiple modules, in your case I suggest to have:

  • a “runtime” module (that can be used both inside the Editor and that will be packaged in the final application build);
  • an “editor” module (that will have access to the “runtime” module and will be able to integrate with the editor).

This is the generic organisation for the above scenario:

MyPlugin\
    MyPlugin.uplugin
    Source\
        MyPlugin\          (usually this is the runtime module)
            MyPlugin.Build.cs
        MyPluginEditor\    (usually this is the editor module)
            MyPluginEditor.Build.cs

In the MyPlugin.uplugin file you must list both the modules, each one with the correct Type property:

    "Modules": [
        {
            "Name": "MyPlugin",
            "Type": "Runtime",
            "LoadingPhase": "Default"
        },
        {
            "Name": "MyPluginEditor",
            "Type": "Editor",
            "LoadingPhase": "Default"
        }
    ]

In the file MyPluginEditor.Build.cs you must add the dependency to your runtime module (MyPlugin):

PrivateDependencyModuleNames.AddRange(new string[] {
  "MyPlugin"
});

If instead of the above setup you want to use a single module, then you can explicitly check for Editor builds in your Build.cs files:

if (Target.bBuildEditor)
{
    PrivateDependencyModuleNames.Add("UnrealEd");
}

And use #if WITH_EDITOR/#if WITH_EDITORONLY_DATA and similar to wrap your editor code.

5 Likes

Hi!
Like stated above, I added a second module to my plugin but I cannot import the module into the other…
I keep getting unresolved external symbol errors when im loading the module! I looked for hours and cant find the answer why… Am i missing something? ( I did exactly what was specified above)

Hello @Doudinvillier, did you add your new module to this list?

hi Klian

Yes I did, it allowed me to include the .h file. But I get this error when instantiating the class…

it’s so weird. I started over, created my plugin from scratch, added a second module and it stills doesnt work. Im using UE5.1.
It is because im creating my 2nd module by creating another plugin and copying the files as a 2nd module to my plugin?

maybe something that has to do with the path of my module files not specified somewhere after i move them?

Kafumanto would you have any input? thanks so much for the help, it’s driving me crazy

Is it possible for you to share the plugin, so folks can take a look and see what might be going wrong?

It does seem likely to me that it’s because you’re creating an entire second plugin and trying to copy things in, yes.