我是 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 存储库进行了比较,但找不到任何差异。我使用的是虚幻编辑器 4.16.0!
我注意到另一个奇怪的事情:当我从虚幻引擎编辑器编译所有内容时,它编译并运行良好。但是当我用 VS 2017 编译它时,我得到了错误,而且我也没有得到自动完成,这真是太糟糕了。我缺少什么?