我是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_中編譯的意思。 –