【发布时间】:2017-10-28 10:10:39
【问题描述】:
我是 UE4 开发的新手,我学习了 Udemy 的虚幻引擎开发课程。我在 Actor 上创建了一个新组件,名为 PositionReporter,标题为 PositionReporter.h
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UPositionReporter : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UPositionReporter();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
PositionReporter.cpp 中的代码
#include "PositionReporter.h"
// Sets default values for this component's properties
UPositionReporter::UPositionReporter()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UPositionReporter::BeginPlay()
{
Super::BeginPlay();
FString t = GetOwner()->GetActorLabel();
UE_LOG(LogTemp, Warning, TEXT("Position Reporter reporting for duty on %s"), *t);
}
// Called every frame
void UPositionReporter::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
如您所见,我现在尝试在指向通过 GetObject() 检索的 AActor 的指针上调用 GetName 函数。
但是,只要我键入“GetObject()->”,就不会弹出自动完成功能(就像在视频中那样),当我手动添加“GetName()”时,我会收到编译器错误“指向不完整类的指针类型不允许”。
做错了什么?我错过了进口吗?我已经将我的代码与 Ben 的 git repo 进行了比较,但找不到任何差异。我在虚幻编辑器 4.16.0 上!
我注意到另一个奇怪的事情:当我从虚幻引擎编辑器编译所有内容时,它编译并运行良好。但是当我用 VS 2017 编译它时,我得到了错误,而且我也没有得到自动完成,这真是太糟糕了。我错过了什么?
【问题讨论】:
-
“我错过了什么?” 包含一些包含必要声明的头文件可能吗?
-
如果它在引擎中编译,但 VS 2017 给我一个错误,我对此表示怀疑。 “也许”-答案不是很有帮助,顺便说一句...
-
这就是为什么它是评论而不是答案。这肯定是关于缺少声明。我不知道它是什么意思它在引擎中编译。
-
当我在引擎中点击编译时它可以工作。刚刚发现它也可以在 VS 2017 中构建。但我仍然会在编码时得到错误,即使它编译得很好!
-
这里有同样的问题:/ 在这里链接了问题:github.com/UnrealCourse/03_BuildingEscape/issues/2
标签: c++ unreal-engine4