no generated.h file

I am testing a unreal project based on engine 4.11 with a 3rd party plugin. After “generate visual studio project file”, when compiling, VS complains there is no XXX.generated.h file where XXX.h is a header file provided by 3rd plugin. The 3rd plugin is detectable by unreal. So I don’t know why such generated.h file is not automatically generated. Any ideas?

Those header files are created at compile time by Unreal Header Tool so they don’t exist straight away. Something is going wrong during UHT’s parsing process.

generated.h files are also only required if the header file has any unreal-specific types like UCLASS, UENUM, USTRUCT etc. If the file doesn’t contain any of those, it doesn’t need the generated.h and UHT won’t create one for it.

Where have you placed the plug-in in your project folder? And did you delete all these folders before re-creating the solution file - and does the file in question have any UE-types like i mentioned above?

1 Like

Where have you placed the plug-in in your project folder?

It is in C:\Program Files\Epic Games\UE_4.11\Engine\Plugins.

And did you delete all these folders before re-creating the solution file - and does the file in question have any UE-types like i mentioned above?

Yes, I think so. For example, there is no Intermediate or Binaries folders before project files generating. And the plugin “OptitrackNatNet” was also defined in the Build.cs file as shown below.


using UnrealBuildTool;

public class OffAxisWindow : ModuleRules
{
public OffAxisWindow(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “HeadMountedDisplay”, “OptitrackNatNet”});

PrivateDependencyModuleNames.AddRange(new string] { “Slate”, “SlateCore” });

PublicIncludePaths.AddRange(new string] { “OptitrackNatNet/Public”, “OptitrackNatNet/Classes” });
}
}

I’m fairly sure that if you’re putting it in the engine folder then the plug-in won’t be built with your project, it needs to be in your project folder structure or pre-compiled with the engine.

Could you explain more?

  1. I have tried to put the plugin folder in my project folder in different locations, but doesn’t work. Where should I put it? What’s more, I don’t how the “Generate visual studio project files” can find such plugin files.

  2. By pre-complied with the engine, you mean, I should build the engine from the source with the plugin folder in it?

If you want it to be an Engine Plugin, you need to put it in Engine/Plugin and rebuild the Engine from source. The “Generate Visual Studio” step will search out all the *.build.cs files and should find your plugin. That’s the easiest option IMO.

Thanks! Rebuilding the engine solved this issue!

for anyone with the same issue.

English Version

  1. add a new *.h file
  2. add the following code
    #include "CoreMinimal.h"
    
    USTRUCT(BlueprintType)
    struct FMyNewStruct
    {
    	GENERATED_BODY()
    };
    
    • Note: Struct name start with F
    • Note: GENERATED_BODY is required
  3. Build Solution
    • Note: there will be compile error, just ignore
    • Note: you can not find the new struct in UE Editor
    • Note: this compile action will start UnrealHeaderTool that will generate *.generated.h
  4. Edit code,include *.generated.h
    #include "CoreMinimal.h"
    #include "MyNewStruct.generated.h"
    
    USTRUCT(BlueprintType)
    struct FMyNewStruct
    {
    	GENERATED_BODY()
    };
    
  5. Build Solution AGAIN!
    • build will success
    • and struct can be found in UE Editor

中文版

  1. 在工程目录添加一个.h文件
  2. 添加如下代码
    #include "CoreMinimal.h"
    
    USTRUCT(BlueprintType)
    struct FMyNewStruct
    {
    	GENERATED_BODY()
    };
    
    • 注意:Struct必须以F开头
    • 注意:GENERATED_BODY不能省去
  3. 生成项目
    • 注意,此时会报错,不用关注
    • 注意,此时在UE编辑器中仍旧找不到该新建Struct
    • 此次编译的目的:触发一次UnrealHeaderTool,生成文件对应的.generated.h文件
  4. 修改代码,包含.generated.h
    #include "CoreMinimal.h"
    #include "MyNewStruct.generated.h"
    
    USTRUCT(BlueprintType)
    struct FMyNewStruct
    {
    	GENERATED_BODY()
    };
    
  5. 再次生成项目
    • 此时可以成功编译
    • 引擎中也能找到类型定义
2 Likes