How to deal with Editor-only Modules in non-Editor build targets?

Hello,

My project depends on a plugin, and said plugin depends on “UnrealEd” module.
I need to make it build as Cooked non-Editor Target (e.g. “Shipping”).

In [project].build.cs the plugin module gets included as private dependency.
In [plugin].build.cs the “UnrealEd” module is also getting included as private dependency.
All code written in the plugin that depends on headers from “UnrealEd” is wrapped by #if WITH_EDITOR preprocesor directive.
in [plugin].uplugin the “Type” is set to “Runtime”

Whenever I try to build “Shipping” target, I am getting following error:

Unable to instantiate module 'UnrealEd': Unable to instantiate UnrealEd module for non-editor targets.
(referenced via Target -> [plugin].Build.cs)

I believe that this is caused by setting the plugin to “Runtime” type.
However, I need to use this module at runtime during gameplay.

I fought that having a module as private dependency will be enough to prevent it from getting included in some build targets, but this doesn’t seem to work such way.

I’m struggling to figure this out. Am I missing something?
Is there any way to solve this?

Thanks!

I tried to fix it by moving the code dependent on “UnrealEd” to yet another module, let’s call this module “PluginEditor”.

So now my plugin has two modules - “PluginRuntime” and “PluginEditor”

and [plugin].uplugin contains:

"Modules": [
	{
		"Name": "PluginEditor",
		"Type": "Editor",
		"LoadingPhase": "PreDefault"
	},
	{
		"Name": "PluginRuntime",
		"Type": "Runtime",
		"LoadingPhase": "Default"
	}
]

[project].Build.cs contains:

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

PluginCore.Build.cs contains:

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

and PluginEditor.Build.cs contains:

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

According to Plugins in Unreal Engine | Unreal Engine 5.2 Documentation
this now should build in the Shipping, right? Right???
NO, it doesn’t, at least not for me:

Unable to instantiate module 'UnrealEd': Unable to instantiate UnrealEd module for non-editor targets.
(referenced via Target -> PluginCore.Build.cs -> PluginEditor.Build.cs)

(toooo bad…)

I have no idea what I’m doing wrong.
Feeling hopeless at this point.

Okey, found the solution, here:

Changing module “Type” did nothing in my case.

I merged the two modules back to only one and used the following condition in [plugin].Build.cs :

if (Target.bBuildEditor)
{
    PublicDependencyModuleNames.AddRange(new string[]{"UnrealEd",});
}

I also had to wrap every header that comes from “UnrealEd” with #if WITH_EDITOR

My project finally compiles to Shipping :relieved:

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.