Download

UnrealEd Dependency Causes Package Failure

Might anyone know why including “UnrealEd” in Private or Public dependencies in Game.build.cs causes an UnrealBuildTool failure?

If you create a C++ ShooterGame project and add that dependency it will fail to package. Not sure if there is another dependency to include or a missing .dll somewhere?

You will need to create a separate editor-only module if you plan on using stuff from UnrealEd in your game. Add the dependency to that module instead of your runtime module, and don’t include it when cooking.

For example, QAGame.uproject looks like this:


{
	"FileVersion": 3,
	"EngineVersion": "1595950",
	"PackageFileUE4Version": "226",
	"PackageFileLicenseeUE4Version": "0",
	"Modules": 
		{
			"Name": "QAGame",
			"Type": "Runtime",
			"LoadingPhase": "Default"
		},
		{
			"Name": "QAGameEditor",
			"Type": "Editor",
			"LoadingPhase": "Default"
		}
	]
}

Cheers,
Michael Noland

Michael, thank you very much for the quick response!

I’ve setup a new module that encapsulates my editor code and I am able to get it to compile. However when I package I still run into the same issue, I thought the ‘Type’:‘Editor’ would take care of the ‘don’t include it when cooking’ part of your suggestion but I’m guessing that is not enough.

Might anyone know how can I make it so that my new editor module is not included when I package the game?

Make sure you aren’t depending on the module in your Target.cs when doing a game build in your SetupBinaries. You’d want to do something like this if you have to link it into the game in an editor build:



        if (UEBuildConfiguration.bBuildEditor)
        {
            OutExtraModuleNames.Add("QAGameEditor");
        }

Cheers,
Michael Noland

Hmm so if I add my ‘ShooterGameEditor’ module to either the Private/PublicDependencyModuleNames then I can #include “ShooterGameEditor.h” where I want to access the editor code and everything works great in the editor. However, when packaging the game I get an UnrealBuildTool failure as previously noted.

If I remove the ‘ShooterGameEditor’ module from Private/PublicDependencyModuleNames and instead include it

if (UEBuildConfiguration.bBuildEditor)
{
OutExtraModuleNames.Add(“ShooterGameEditor”);
}

within the respective Target.cs files this causes the compiler to complain of a ‘fatal error C1083: Cannot open include file: ‘ShooterGameEditor.h’: No such file or directory’

So I’m not really sure how I can solve this, I’ve followed these two approaches and a combination of both to no avail :\

approach 1) What is the proper method for extending the Editor Engine? - UE4 AnswerHub
approach 2) Gameplay Modules | Unreal Engine Documentation

Use #if WITH_EDITOR around code you want to exclude from runtime builds, but ideally your runtime code doesn’t depend on your editor code (only the other way around). What is your specific use case?

Cheers,
Michael Noland

I was able to resolve this by checking if the build was an editor build before including ‘UnrealEd’ dependency and wrapping the code that depends on it with #if WITH_EDITOR



        if (UEBuildConfiguration.bBuildEditor)//we only want this to be included for editor builds but not packaged builds
        {
            PublicDependencyModuleNames.AddRange(
                new string] {
                    "UnrealEd",
			    }
            );
        }




#if WITH_EDITOR
#include "LevelUtils.h"
#include "LevelEditor.h"
#endif
...

bool ADoWPlayerController::IsGameMultiplePIE()
{
	bool IsGamePie = (GetWorld()->WorldType == EWorldType::PIE);
	bool IsDedicated = false;
	int32 NumberOfClients = 0;

#if WITH_EDITOR
	ULevelEditorPlaySettings* PlayInSettings = Cast<ULevelEditorPlaySettings>(ULevelEditorPlaySettings::StaticClass()->GetDefaultObject());
	PlayInSettings->GetPlayNetDedicated(IsDedicated);
	PlayInSettings->GetPlayNumberOfClients(NumberOfClients);
#endif

	return IsGamePie && (NumberOfClients > 1 || IsDedicated);
}


Thank you Michael for the help!

Working code from 2020.

*.Build.cs:



using UnrealBuildTool;

public class TanksVr : ModuleRules
{
    public TanksVr(ReadOnlyTargetRules target) : base(target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
        bEnforceIWYU = true;

        PublicDependencyModuleNames.AddRange(new ]
             {
                    "Core",
                    "CoreUObject",
                    "Engine",
                    "PhysXVehicles",
                    "HeadMountedDisplay",
                    "InputCore",
                    "Networking",
                    "Sockets",
                    "Json",
                    "JsonUtilities",
                    "GameplayAbilities",
                    "GameplayTags",
                    "GameplayTasks",
                    "AIModule",
               });

          if (target.bBuildEditor)
          {
               PublicDependencyModuleNames.AddRange(new ]
                    {
                         "UnrealEd",
                    });
          }
     }
}


Somewhere in code:



#if WITH_EDITOR
#include "UnrealEd.h"
#endif

......

void ATankSpawnPointSelector::UpdateDrawing()
{
#if WITH_EDITOR
     if (GEditor != nullptr)
     {
          GEditor->RedrawLevelEditingViewports();
     }
#endif
}


Dude, loving you @Elapotp