Cannot include .generated.h but it exists

Hello,

I’m currently trying to add a custom module to my game, but I got a class in this new module that fails to compile because it cannot include it’s generated.h file

Here is the header of the class :

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameStateBase.h"
#include <map>
#include "Kea/Characters/Components/HealthComponent.h"
#include "EntityManager.generated.h"

/**
 * 
 */
UCLASS()
class SKILLCASTERMODULE_API AEntityManager : public AGameStateBase
{
	GENERATED_BODY()

public:
	AEntityManager();
	std::map<int, AActor*> EntityMap;	
	void AddEntity(int, AActor*);
};

This gives me this error :

Cannot open include file: 'EntityManager.generated.h': No such file or directory

2nd time writing this because the web server boned me…again.

Try rebuilding everything from scratch. If you don’t know how, here it is:

  1. Exit the editor and back up the project (just in case)
  2. Delete these directories from your project folder tree: .vs, Binaries, Build, Debug, Intermediate, Saved
  3. Re-generate project files (right-click your uproject file and choose “Generate Project Files”)
  4. Open the Visual Studio solution (YourProject.sln)
  5. Build your project for “Development Editor” (should be set already)

If that doesn’t do it then post your CPP file too I guess.

It does not solve the problem.

Here is my cpp file :

#include "EntityManager.h"
#include "SkillCasterModule.h"
#include "Kea/CLRService.h"	



AEntityManager::AEntityManager()
{
	PrimaryActorTick.bCanEverTick = true;
	EntityMap = std::map<int, AActor*>();
}

void AEntityManager::AddEntity(int id, AActor* actor)
{
	EntityMap.insert(std::pair<int, AActor *>(id, actor));
	CLRService* service = CLRService::GetService();
	if (service)
	{
		HINSTANCE dllHandle = service->GetDllHandle();
		if (dllHandle)
		{
			IntParameterFunc func = (IntParameterFunc)GetProcAddress(dllHandle, "AddCharacter");
			if (func)
			{
				func(id);
			}
		}
	}
}

Responding to below…

EntityManager.cpp is in the solution, getting built? Is it building EntityManager.gen.cpp? (It will only build it the first time, FYI.) Is there another error before the missing file error?

Does an unaltered C++ template project build OK?

If so, it must be how you’re doing this custom module. The file isn’t getting generated so something must be wrong there. You’ll need to provide more details about the module and how you project is set up.

I’ve succeed to correct this by adding the class through Unreal editor

I’ve had the same problem recently.
My problem was including the header file in a different module (let’s call it ForeignModule) with path like this:

#include "MyModule/Public/MyClass.h"

The correct solution was to include:

#include "MyClass.h"

And add "MyModule" to the ForeignModule.Build.cs file.

1 Like

I had exactly the same error. Thanks a lot!