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了。

  • 相关阅读:
    request.getParameter() 、 request.getInputStream()和request.getReader() 使用体会
    HTTP之Content-Length
    关于spring3中No Session found for current thread!and Transaction的配置和管理(转)
    Java数据类型和MySql数据类型对应一览
    Spring MVC 解读——View,ViewResolver(转)
    LeetCode 441. Arranging Coins
    LeetCode 415. Add Strings
    LeetCode 400. Nth Digit
    LeetCode 367. Valid Perfect Square
    LeetCode 326. Power of Three
  • 原文地址:https://www.cnblogs.com/Again/p/6365991.html
Copyright © 2011-2022 走看看