UE4数据表结构错误

时间:2017-08-01 20:20:51

标签: c++ visual-c++ unreal-engine4

我正在关注有关CSV表格条目的Packt教程。本教程要求我 a)创建一个新的Actor类, b)将其命名为TestCustomData, c)替换新的内容使用以下代码生成TestCustomData.h:

#pragma once

#include "TestCustomData.generated.h"

USTRUCT(BlueprintType)
struct FTestCustomData : public FTableRowBase
{
GENERATED_USTRUCT_BODY()

UPROPERTY( BlueprintReadOnly, Category = "TestCustomData" )
int32 SomeNumber;

UPROPERTY( BlueprintReadOnly, Category = "TestCustomData" )
FString SomeString;
};

但是,TestCustomData文件无法编译,输出以下日志:

Error f:\unreal\ue4 assignments\ue4_projectrpg\source\ue4_projectrpg\TestCustomData.h(5) : error C2504: 'FTableRowBase': base class undefined
Info Compiling game modules for hot reload
Info Parsing headers for UE4_ProjectRPGEditor
Info   Running UnrealHeaderTool "F:\Unreal\UE4 Assignments\UE4_ProjectRPG\UE4_ProjectRPG.uproject" "F:\Unreal\UE4 Assignments\UE4_ProjectRPG\Intermediate\Build\Win64\UE4_ProjectRPGEditor\Development\UE4_ProjectRPGEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
Info Reflection code generated for UE4_ProjectRPGEditor in 3.4146568 seconds
Info Performing 4 actions (4 in parallel)
Info TestCustomData.cpp
Info UE4_ProjectRPG.generated.cpp
Error f:\unreal\ue4 assignments\ue4_projectrpg\source\ue4_projectrpg\TestCustomData.h(6) : error C3646: 'Super': unknown override specifier
Error f:\unreal\ue4 assignments\ue4_projectrpg\source\ue4_projectrpg\TestCustomData.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error F:\Unreal\UE4 Assignments\UE4_ProjectRPG\Source\UE4_ProjectRPG\TestCustomData.h(5) : error C2504: 'FTableRowBase': base class undefined
Error F:\Unreal\UE4 Assignments\UE4_ProjectRPG\Source\UE4_ProjectRPG\TestCustomData.h(6) : error C3646: 'Super': unknown override specifier
Error F:\Unreal\UE4 Assignments\UE4_ProjectRPG\Source\UE4_ProjectRPG\TestCustomData.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Info ERROR: UBT ERROR: Failed to produce item: F:\Unreal\UE4 Assignments\UE4_ProjectRPG\Binaries\Win64\UE4Editor-UE4_ProjectRPG-3031.dll
Info Total build time: 6.88 seconds (Local executor: 0.00 seconds)

我对UE4中的StackOverflow和C ++相当新,任何帮助都将不胜感激。任何改善我的问题的反馈也是受欢迎的!在此先感谢您的帮助。

4 个答案:

答案 0 :(得分:1)

我被困在同一个地方并修复了它: 我将资产命名为“MyActor2”和Strucure“ThisNewStructure”,因此存在一些差异......

我认为基本上包括Datatable.h和“public:”就可以了。

标题文件:

// get all the posts
Posts.find((err, posts)=> {

  if (err) { next(err) };
  var data = Array();
  var count = 0;
  var len = posts.length;
  // function to check the end of inner queries
  var checkloop = function(){
    count++;
    if(count===len)
        return res.json({result:data,
                msg:'success'});
    }

  for(var i=0;i<len;i++){

    Users.findOne({email:posts[count].authEmail},(err,usr)=>{

    if(usr){
        var item = {
                    'authorName':usr.name?
                    'email':usr.email,
                    'postDesc':posts[count].desc,
                    'creationTime':posts[count].time
                    }
        data.push(item);

        }
        checkloop();
    });

    }

});

CPP:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Engine/DataTable.h"
#include "MyActor2.generated.h"

USTRUCT(BlueprintType)
struct FThisNewStructure : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()
public:

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = test)
        int32 SomeNumber;
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = test)
        FString SomeString;

};

然后它编译成功。 我不得不关闭/重新开启VS&amp; UE让编辑了解新结构。

答案 1 :(得分:0)

乍一看,似乎没有包含描述FTableRowBase的头文件。您在输出中看到的错误 - “缺少类型说明符”等表明您的编译器不知道FTableRowBase是什么,因此无法从中获取。包括描述父类的标题应该解决这个问题。

答案 2 :(得分:0)

可能有点晚了,但我自己就碰到了这个。有时你会有一个自动获取FTableRowBase的包含,但有时一个类没有一个回调它的标题。在那种情况下:

#pragma once

#include "Engine/DataTable.h"//this is where FTableRowBase is declared.
#include "TestCustomData.generated.h"

struct FFoo : FTableRowBase
{
    GENERATED_USTRUCT_BODY()
    public:
       the rest of your class...

我希望这有帮助! :d

答案 3 :(得分:0)

感谢您的帮助,我在同一个教程中解决了同样的问题。显然你不需要将TestCustomData重命名为MyActor2,你只需要添加一行&#34; public:&#34;在&#34; GENERATED_USTRUCT_BODY()&#34;。

之后