no generated.h file

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