Updating project to UE5 from UE4.26 fails to build with error "Could not find definition for module '"

Hi there,

I have a project (started originally on UE4’s initial version) which I have been upgrading over time to keep up with new features. It was on version 4.26 and building successfully. This project is a C++ one and I have a significant number of custom classes etc.

I have downloaded the latest UE5 source code and built the engine successfully. However, when trying to build my project, I am getting a persistent error which I don’t know how to fix.

When I build the project, the following is in the output log:

1>Invalidating makefile for RoguelikeEditor (RoguelikeEditor.Target.cs modified)
1>Could not find definition for module 'Roguelike', (referenced via RoguelikeEditor.Target.cs)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.MakeFile.Targets(44,5): error MSB3073: The command "C:\UE5\UnrealEngine\Engine\Build\BatchFiles\Build.bat -Target="RoguelikeEditor Win64 Development -Project=\"H:\Unreal Engine 4 Projects\Unreal Projects\<project name>\Roguelike.uproject\"" -Target="ShaderCompileWorker Win64 Development -Quiet" -WaitMutex -FromMsBuild" exited with code 6.
1>Done building project "Roguelike.vcxproj" -- FAILED.

This is an issue I haven’t encountered before.

My target files look like this:

using UnrealBuildTool;
using System.Collections.Generic;
using System;

public class RoguelikeTarget : TargetRules
{
	public RoguelikeTarget(TargetInfo Target) :base(Target)
	{
		Type = TargetType.Game;

        DefaultBuildSettings = BuildSettingsVersion.V2;

        ExtraModuleNames.AddRange(new string[] { "Roguelike" });
	}
}

and:

using UnrealBuildTool;
using System.Collections.Generic;
using System;

public class RoguelikeEditorTarget : TargetRules
{
    public RoguelikeEditorTarget(TargetInfo Target) : base(Target)
    {
        Type = TargetType.Editor;

        DefaultBuildSettings = BuildSettingsVersion.V2;

        ExtraModuleNames.AddRange(new string[] { "Roguelike" });
    }
}

I am building in Development Editor Win64 configuration.

Interestingly if I comment out the lines in the target files starting ExtraModuleNames.Add

Then the project will actually build. However, when I start it I get the warning “Roguelike was built with a different version, would you like to rebuild?” If I select yes, it fails and tells me to build from the source.

I am using VS 2022.

Any tips would be hugely appreciated, I have exhausted all avenues so far. Is there an issue with the build agent finding the compiled c++ module?

Updating to add that I’ve had no luck tinkering with the .cs files. Is there a way to autogenerate these?

Could be you are missing the module implementation.

Roguelike.cpp

#include "Roguelike.h"


void FPrimaryGameModuleImpl::StartupModule() {
}

void FPrimaryGameModuleImpl::ShutdownModule() {
}


IMPLEMENT_PRIMARY_GAME_MODULE(FPrimaryGameModuleImpl, Roguelike, "Roguelike");

Roguelike.h

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"


class ROGUELIKE_API FPrimaryGameModuleImpl : public FDefaultGameModuleImpl {

public:

	/** IModuleInterface implementation */
	virtual void StartupModule() override;

	virtual void ShutdownModule() override;
	/** End IModuleInterface implementation */

};
2 Likes

There is no way to auto generate these at least not accurately, it would have to guess what modules to require from the header files? That is not going to work.

You also need the YourClass.Build.cs file in the same folder as the .cpp and .h mentioned in the previous post, as that sets module rules.

Something like:

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class YourClass : ModuleRules
{
public YourClass(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

  PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

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

  // Uncomment if you are using Slate UI
  // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
  
  // Uncomment if you are using online features
  // PrivateDependencyModuleNames.Add("OnlineSubsystem");

  // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true

}
}