zoukankan      html  css  js  c++  java
  • UE4 无法include “filename.generated.h”

    在做plugin的时候要添加功能代码,添加的类无法编译通过。提示需要包含.generated.h 但是编译不通过又没有这个文件。

    这就尴尬了。

    下面提供最简单的配置,通过复制下面代码。编译通过后再自行扩建

    代码结构如下:红框内是我需要新增的一个类 ImageLoaderComponent

    ImageLoaderPrivatePCH.h

    // Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
    
    
    
    // You should place include statements to your module's private header files here.  You only need to
    // add includes for headers that are used in most of your module's source files though.
    // 
    
    #include "CoreUObject.h"
    #include "Engine.h"
    #include "ImageLoader.h"    //你自己模块的.h文件

    内部公共头文件需要引用 Engine 和 Uobject , 还有你自己模块的模块头文件

    ImageLoaderComponent.h

    // Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
    
    #pragma once
    #include "ImageLoaderComponent.generated.h"
    
    /************************************************************************/
    /*  你自己的类                                                           */
    /************************************************************************/
    
    UCLASS()
    class UImageLoaderComponent : public UObject
    {
        GENERATED_UCLASS_BODY()
    
    
    };

    新建的类需要引用 filename.generated.h ,因为可能涉及到引擎模块库的调用,所以需要用generated做热部署相关的工作(猜的)

    以后头文件的引用列表不需要扩展,扩展的时候放到PCH文件里,譬如引用了其他库,或者其他引擎功能,在PCH中添加引用,并于Build.cs中添加关联

    ImageLoaderComponent.cpp

    // Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
    
    
    #include "ImageLoaderPrivatePCH.h"
    #include "ImageLoaderComponent.h"
    
    /************************************************************************/
    /*  你自己的类实现(构造函数)                                              */
    /************************************************************************/
    
    UImageLoaderComponent::UImageLoaderComponent(const FObjectInitializer& ObjectInitializer)
        : Super(ObjectInitializer)
    {
        
    }

    实现文件当然引用 PCH 以及这个类的声明文件。

    使用过程中除了PCH引用了的库外,内部使用过程中用到的.h写在当前cpp这里,防止文件污染。

    然后编译通过后就可以欢快地使用UE了。

  • 相关阅读:
    Python实现天数倒计时计算
    pandas 的数据结构Series与DataFrame
    在python中使用静态方法staticmethod
    python 中对list做减法操作
    推荐系统之 BPR 算法及 Librec的BPR算法实现【1】
    机器学习中的 ground truth
    PyCharm 默认运行 unittest
    Python的copy()与deepcopy()区别
    MySQL中Decimal类型和Float Double的区别 & BigDecimal与Double使用场景
    Spring Boot 返回 JSON 数据,一分钟搞定!
  • 原文地址:https://www.cnblogs.com/Again/p/6365991.html
Copyright © 2011-2022 走看看