我是UE4开发新手,我遵循Udemy的虚幻引擎开发课程。我已经创建上演员的新组件,在PositionReporter.cpp命名PositionReporter与头PositionReporter.hAActor * UactorComponent :: GetOwner const - 不允许指向不完整的类类型的指针
#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;
};
和代码是
#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进行编译时,出现错误,而且我也没有得到Autocomplete,这是一个真正的失望。我错过了什么?
_“我缺少什么?”_要包含一些包含必要声明的头文件,也许? –
如果它在引擎中编译,但VS 2017给我一个错误,我怀疑这一点。 “也许”-answers不是很有帮助,btw ... – Christian
这就是为什么它是一个评论,而不是一个答案。这是关于错过声明。我不知道它在engine_中编译的意思。 –